题号:1004
这题还是比较简单的……虽然我看了题解,但是还是能看得懂的。。
参考题解:https://www.luogu.org/wiki/show?name=%E9%A2%98%E8%A7%A3+P1004
作者: sb123 更新时间: 2017-08-07 14:52
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include<iostream> #include<algorithm> #include<string> #include<utility> #include<queue> #include<cstdlib> #include<cstring> #include<map> using namespace std; int n; int f[12][12][12][12],arr[12][12]; int main(){ ios::sync_with_stdio(false); cin >> n; int rf1, rf2, rf3; while (cin >> rf1 >> rf2 >> rf3){ if (rf1 == 0 && rf2 == 0 && rf3 == 0)break; arr[rf1][rf2] = rf3; } for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ for (int k = 1; k <= n; k++){ for (int l = 1; l <= n; l++){ f[i][j][k][l] = max(f[i - 1][j][k - 1][l], f[i][j - 1][k - 1][l]); f[i][j][k][l] = max(f[i][j][k][l], f[i - 1][j][k][l - 1]); f[i][j][k][l] = max(f[i][j][k][l], f[i][j - 1][k][l - 1]); if (i == k && j == l)f[i][j][k][l] += arr[i][j]; else f[i][j][k][l] += arr[i][j] + arr[k][l]; } } } } cout << f[n][n][n][n]; } |