|
|
|
@ -343,13 +343,13 @@ int n;
|
|
|
|
|
int m;
|
|
|
|
|
int path[N], res[N];
|
|
|
|
|
int w[N][M];
|
|
|
|
|
int Max;
|
|
|
|
|
int mx;
|
|
|
|
|
|
|
|
|
|
// u:第几个公司 s:已经产生的价值 r:剩余的机器数量
|
|
|
|
|
void dfs(int u, int s, int r) {
|
|
|
|
|
if (u == n + 1) {
|
|
|
|
|
if (s > Max) {
|
|
|
|
|
Max = s;
|
|
|
|
|
if (s > mx) {
|
|
|
|
|
mx = s;
|
|
|
|
|
memcpy(res, path, sizeof path);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
@ -357,25 +357,23 @@ void dfs(int u, int s, int r) {
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i <= r; i++) {
|
|
|
|
|
path[u] = i;
|
|
|
|
|
dfs(u + 1, s + w[u][i], r - i);//给u号公司分配i个机器
|
|
|
|
|
// path[u] = 0;
|
|
|
|
|
//按照回溯法,此处应该写path[u]还原现场,但本题中即使不还原现场,path[u]也会被下一次循环所覆盖,所以这句可以省略掉
|
|
|
|
|
dfs(u + 1, s + w[u][i], r - i); // 给u号公司分配i个机器
|
|
|
|
|
path[u] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
scanf("%d %d", &n, &m);
|
|
|
|
|
cin >> n >> m;
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
|
|
|
for (int j = 1; j <= m; j++)
|
|
|
|
|
scanf("%d", &w[i][j]);
|
|
|
|
|
cin >> w[i][j];
|
|
|
|
|
|
|
|
|
|
dfs(1, 0, m);
|
|
|
|
|
|
|
|
|
|
printf("%d\n", Max);
|
|
|
|
|
//输出最优答案时的路径
|
|
|
|
|
printf("%d\n", mx);
|
|
|
|
|
// 输出最优答案时的路径
|
|
|
|
|
for (int i = 1; i <= n; i++) printf("%d %d\n", i, res[i]);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|