0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:28:47 +00:00

#889. 【SDOI2009】学校食堂

https://sjzezoj.com/submission/64192
This commit is contained in:
Baoshuo Ren 2022-11-12 15:53:19 +08:00
parent 980b9dea24
commit e6d3d9d61a
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
52 changed files with 221 additions and 0 deletions

68
S2OJ/889/889.cpp Normal file
View File

@ -0,0 +1,68 @@
#include <iostream>
#include <cstring>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1005;
const int INF = 0x3f3f3f3f;
int c, n, f[N][1 << 8][20];
std::pair<int, int> a[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> c;
while (c--) {
memset(f, 0x3f, sizeof(f));
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
f[1][0][7] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 1 << 8; j++) {
for (int k = -8; k <= 7; k++) {
if (f[i][j][k + 8] != INF) {
if (j & 1) { // 当前同学吃了,无需考虑后方
f[i + 1][j >> 1][k + 7] = std::min(f[i + 1][j >> 1][k + 7], f[i][j][k + 8]);
} else {
int t = INF;
for (int l = 0; l <= 7; l++) {
if (j & 1 << l) continue;
if (i + l > t) break;
if (i + l <= n) t = std::min(t, i + l + a[i + l].second);
else t = std::min(t, i + l);
if (i + k) {
int x = i + k <= n ? a[i + k].first : 0,
y = i + l <= n ? a[i + l].first : 0;
f[i][j | 1 << l][l + 8] = std::min(f[i][j | 1 << l][l + 8], f[i][j][k + 8] + (x ^ y));
} else {
f[i][j | 1 << l][l + 8] = std::min(f[i][j | 1 << l][l + 8], f[i][j][k + 8]);
}
}
}
}
}
}
}
int ans = INF;
for (int i = 0; i <= 8; i++) {
ans = std::min(ans, f[n + 1][0][i]);
}
cout << ans << endl;
}
return 0;
}

BIN
S2OJ/889/data/data1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data20.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data21.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data21.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data22.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data22.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data23.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data23.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data24.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data24.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data25.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data25.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/data9.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/889/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.