添加注释 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int INF = 1e9; int profit[4][7] = { {0, 0, 0, 0, 0, 0, 0}, {0, 3, 5, 6, 7, 6, 5}, {0, 4, 6, 7, 8, 9, 10}, {0, 2, 5, 9, 8, 8, 7}}; int dp[10][10][10]; int main() { memset(dp, 0, sizeof(dp)); for (int i = 0; i < 7; i++) for (int j = 0; j < 7; j++) for (int k = 0; k < 7; k++) { dp[i][j][k] = max(dp[i][j][k], profit[1][i] + profit[2][j] + profit[3][k]); } int n = 0; cin >> n; int l = -1, r = -1, m = -1, res = -1; for (int i = 0; i < 7; i++) for (int j = 0; j < 7; j++) for (int k = 0; k < 7; k++) if (i + j + k == n && res < dp[i][j][k]) { res = dp[i][j][k]; l = i; r = j; m = k; } printf("%d %d %d\n", l, r, m); cout << "你好" << endl; printf("%d", res); return
时间: 2024-01-27 15:05:24 浏览: 120
下面是添加注释后的代码:
```c++
// 引入头文件
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF = 1e9;
// 定义利润数组
int profit[4][7] = {
{0, 0, 0, 0, 0, 0, 0},
{0, 3, 5, 6, 7, 6, 5},
{0, 4, 6, 7, 8, 9, 10},
{0, 2, 5, 9, 8, 8, 7}
};
// 定义动态规划数组
int dp[10][10][10];
int main() {
// 初始化动态规划数组
memset(dp, 0, sizeof(dp));
for (int i = 0; i < 7; i++)
for (int j = 0; j < 7; j++)
for (int k = 0; k < 7; k++) {
dp[i][j][k] = max(dp[i][j][k], profit[1][i] + profit[2][j] + profit[3][k]);
}
// 读入n值
int n = 0;
cin >> n;
// 计算最大利润
int l = -1, r = -1, m = -1, res = -1;
for (int i = 0; i < 7; i++)
for (int j = 0; j < 7; j++)
for (int k = 0; k < 7; k++)
if (i + j + k == n && res < dp[i][j][k]) {
res = dp[i][j][k];
l = i;
r = j;
m = k;
}
// 输出结果
printf("%d %d %d\n", l, r, m);
cout << "你好" << endl;
printf("%d", res);
return 0;
}
```
阅读全文