Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
你的那个没有初始化,是错的In Reply To:40行代码解决,偶也~发现记忆化搜索比正向递推好用~ Posted by:yzhw at 2010-08-17 18:00:14 #include<iostream> #include<stdio.h> #include<string.h> using namespace std; const int size=510; int n,m; int g[2][size][size],f[2][size][size],s[2][size][size]; int main() { int i,j,k; while(scanf("%d%d",&n,&m)==2) { if(!n&&!m) break; memset(f,0,sizeof(f)); memset(s,0,sizeof(s)); for(i=1;i<=n;i++) for(j=1;j<=m;j++) { scanf("%d",&g[0][i][j]); s[0][i][j]=s[0][i][j-1]+g[0][i][j]; } for(i=1;i<=n;i++) for(j=1;j<=m;j++) { scanf("%d",&g[1][i][j]); s[1][i][j]=s[1][i-1][j]+g[1][i][j]; } for(i=1;i<=n;i++) for(j=1;j<=m;j++) { f[0][i][j]=max(f[0][i-1][j],f[1][i-1][j])+s[0][i][j]; f[1][i][j]=max(f[0][i][j-1],f[1][i][j-1])+s[1][i][j]; } int ans=max(f[0][n][m],f[1][n][m]); printf("%d\n",ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator