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<iostream> using namespace std; #define M 254 int t,m; int n; int num[M][M]; int submax(int a[M]) { int pre; int max=0; pre=a[1]; for(int i=2;i<=n;i++) { if(a[i]+pre>a[i]) pre=a[i]+pre; else pre=a[i]; if(pre>max) max=pre; } return max; } int submax2(int a[][M]) { int max=0; int b[M]; for(int i=1;i<=n;i++) { memset(b,0,sizeof(b)); for(int j=i;j<=n;j++) { for(int k=1;k<=n;k++) b[k]+=a[j][k]; int f=submax(b); if(f>max) max=f; } } return max; } int main() { while(cin>>n) { for( t=1;t<=n;t++) for(m=1;m<=n;m++) cin>>num[t][m]; int max=submax2(num); cout<<max<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator