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 |
找最大值的时候..忘了把m初始。。送了2个WA。。郁闷,dp 0ms#include<iostream> using namespace std; int a[101][101],re[101][101]; int N; int max(int a,int b){return a>b?a:b;} void init() { int i,j; memset(a,0,sizeof(a)); memset(re,0,sizeof(re)); for(i=1;i<=N;i++) for(j=1;j<=i;j++) scanf("%d",a[i]+j); } int dp() { int i,j,m=0; for(i=1;i<=N;i++) for(j=1;j<=i;j++) re[i][j]=max(re[i-1][j],re[i-1][j-1])+a[i][j]; for(i=1;i<=N;i++)m=max(m,re[N][i]); return m; } int main() { while(scanf("%d",&N)!=EOF) { init(); printf("%d\n",dp()); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator