标签:style blog http color io os ar java for
1 3 8 9 10 10 10 10 -10 10 10 10 -11 -1 0 2 11 10 -20 -11 -11 10 11 2 10 -10 -10
52
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 int mp[22][1010],dp[22][1010],n,m; 18 int main() { 19 int t; 20 scanf("%d",&t); 21 while(t--) { 22 scanf("%d %d",&n,&m); 23 for(int i = 0; i <= n; i++) dp[i][0] = -INF; 24 for(int i = 0; i <= m; i++) dp[0][i] = -INF; 25 for(int i = 1; i <= n; i++) { 26 for(int j = 1; j <= m; j++) 27 scanf("%d",mp[i]+j); 28 } 29 for(int i = 1; i <= n; i++) { 30 for(int j = 1; j <= m; j++) { 31 int maxV = -INF; 32 if(i == 1 && j == 1){ 33 dp[i][j] = mp[i][j]; 34 continue; 35 } 36 for(int k = 1; k < j; k++) 37 if(k == j-1 || j%k == 0) maxV = max(maxV,dp[i][k]); 38 dp[i][j] = mp[i][j] + max(maxV,dp[i-1][j]); 39 } 40 } 41 printf("%d\n",dp[n][m]); 42 } 43 return 0; 44 }
标签:style blog http color io os ar java for
原文地址:http://www.cnblogs.com/crackpotisback/p/4003148.html