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

1266. 【例9.10】机器分配

http://ybt.ssoier.cn:8088/statusx.php?runidx=15567712
This commit is contained in:
Baoshuo Ren 2022-04-02 16:29:14 +08:00
parent a538709611
commit 7acf5b0d8d
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

42
ybt/1266/1266.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 15,
M = 20;
int n, m, w[N][M], f[N][M], g[N][M];
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> w[i][j];
}
}
for (int i = n; i >= 1; i--) {
for (int j = m; j >= 0; j--) {
f[i][j] = f[i + 1][j];
for (int k = 1; k <= j; k++) {
if (f[i][j] < f[i + 1][j - k] + w[i][k]) {
f[i][j] = f[i + 1][j - k] + w[i][k];
g[i][j] = k;
}
}
}
}
cout << f[1][m] << endl;
for (int i = 1, j = m; i <= n; i++) {
cout << i << ' ' << g[i][j] << endl;
j -= g[i][j];
}
return 0;
}