记录编号 | 392306 | 评测结果 | AAAAAA | ||
---|---|---|---|---|---|
题目名称 | [NOIP 2000]方格取数 | 最终得分 | 100 | ||
用户昵称 | 是否通过 | 通过 | |||
代码语言 | C++ | 运行时间 | 0.003 s | ||
提交时间 | 2017-04-07 19:05:46 | 内存使用 | 0.37 MiB | ||
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #define mylove Turkey; using namespace std; const int maxn=11; int n,m[maxn][maxn],d[maxn][maxn][maxn][maxn],a,b,c; typedef long long ll; int main() { freopen("fgqs.in","r",stdin); freopen("fgqs.out","w",stdout); scanf("%d",&n); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) m[i][j]=0; while(scanf("%d%d%d",&a,&b,&c)==3) { if(a==0&&b==0&&c==0)break; m[a][b]=c; } for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) for(int k=0;k<=n;k++) for(int h=0;h<=n;h++) d[i][j][k][h]=0; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=1;k<=n;k++) for(int h=1;h<=n;h++) { int tem1=max(d[i-1][j][k-1][h],d[i][j-1][k-1][h]); int tem2=max(d[i-1][j][k][h-1],d[i][j-1][k][h-1]); d[i][j][k][h]=max(tem1,tem2)+m[i][j]; if(i!=k||j!=h)d[i][j][k][h]+=m[k][h]; } cout<<d[n][n][n][n]; fclose(stdin); fclose(stdout); return 0; }