标签:des style blog http java color
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9205 Accepted Submission(s): 3250
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; #define N 505 #define INF 0x3f3f3f3f int ma[25][1005],dp[25][1005]; int main() { int n,m,i,j,k,t; scanf("%d",&t); while(t--) { scanf("%d %d",&n,&m); for(i = 1;i <= n;i++) for(j = 1 ; j <= m ; j++) { scanf("%d",&ma[i][j]); dp[i][j] = -INF; } dp[1][1] = ma[1][1]; for(i = 2 ;i <= m ;i++) { dp[1][i] = max(dp[1][i],dp[1][i-1]+ma[1][i]); for(j = i-1 ; j>=1;j--) { if(i%j==0) dp[1][i] = max(dp[1][i],dp[1][j]+ma[1][i]); } } for(i = 2; i<=n ; i++) dp[i][1] = dp[i-1][1]+ma[i][1]; for(i = 2 ; i <= n ; i++) { for(j = 2 ; j <= m ; j++) { dp[i][j] = max(dp[i-1][j]+ma[i][j],dp[i][j-1]+ma[i][j]); for(k = j-1 ; k>=1 ; k--) if(j%k==0) dp[i][j]= max(dp[i][j],dp[i][k]+ma[i][j]); } } printf("%d\n",dp[n][m]); } return 0; }
标签:des style blog http java color
原文地址:http://www.cnblogs.com/llei1573/p/3847895.html