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 |
求大神,。,。解答#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define M 108 int map[M][M]; int dp[M][M]; int max(int x,int y) { if(x>y) return x; else return y; } int main() { int i,j,k,r,c,t1; while(~scanf("%d%d",&r,&c)) { for(i=1;i<=r;i++) for(j=1;j<=c;j++) { scanf("%d",&map[i][j]); } for(i=1;i<=r;i++) for(j=1,t1=-100000;j<=c;j++) { dp[i][j]=-1000000; } for(i=1;i<=r;i++) for(j=i,t1=-100000;j<=c;j++) { if(i==1) { dp[i][j]=max(t1,map[i][j]); t1=dp[i][j]; } else { dp[i][j]=(map[i][j]+dp[i-1][j-1]); } } /* for(i=1;i<=r;i++) { for(j=1;j<=c;j++) { printf("%9d ",dp[i][j]); } printf("\n"); }*/ for(i=1,t1=-10000000;i<=c;i++) { if(dp[r][i]>t1) { t1=dp[r][i]; } } printf("%d\n",t1+1); // printf("%d\n",dp[r][c]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator