标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14555 Accepted Submission(s): 5119
1 #include <cstring> 2 #include <algorithm> 3 #include <cstdio> 4 #include <iostream> 5 using namespace std; 6 #define Max 1005 7 int dp[25][Max]; 8 int map[25][Max]; 9 int main() 10 { 11 int T,n,m; 12 int i,j,k; 13 freopen("in.txt","r",stdin); 14 scanf("%d",&T); 15 while(T--) 16 { 17 scanf("%d%d",&n,&m); 18 memset(dp,0,sizeof(dp)); 19 for(i=1;i<=n;i++) 20 for(j=1;j<=m;j++) 21 scanf("%d",&map[i][j]); 22 for(i=1;i<=n;i++) 23 { 24 if(i==1) 25 dp[i][1]=map[i][1]; 26 else 27 dp[i][1]=dp[i-1][1]+map[i][1]; 28 for(j=2;j<=m;j++) 29 { 30 if(i!=1) 31 dp[i][j]=max(dp[i][j-1],dp[i-1][j])+map[i][j]; 32 else 33 dp[i][j]=map[i][j]+dp[i][j-1]; 34 for(k=1;k<j;k++) 35 { 36 if(j%k==0) 37 dp[i][j]=max(dp[i][j],dp[i][k]+map[i][j]); 38 } 39 } 40 } 41 printf("%d\n",dp[n][m]); 42 } 43 return 0; 44 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/5276978.html