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 |
还是得感谢算导啊!!DP第一题(附代码)#include <stdio.h> int main () { int a[350][350];int n;int N;int max,i,j,k;int m; for(i=0;i<350;i++) for (j=0;j<350;j++) a[i][j]=0; scanf("%d",&N); for(k=0;k<N;k++) for (m=0;m<=k;m++) scanf("%d",&a[k][m]); a[1][0]=a[0][0]+a[1][0]; a[1][1]=a[0][0]+a[1][1]; for (n=2;n<N;n++) { a[n][0]=a[n-1][0]+a[n][0]; a[n][n]=a[n-1][n-1]+a[n][n]; for (j=1;j<n;j++) { if (a[n-1][j]>a[n-1][j-1]) a[n][j]=(a[n-1][j]+a[n][j]); else a[n][j]=(a[n-1][j-1]+a[n][j]); } } max=a[N-1][0]; for (k=0;k<N;k++) if (a[N-1][k]>max) max=a[N-1][k]; printf("%d\n",max); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator