标签:des c style class blog code
Time Limit: 2000/1000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 2911 Accepted
Submission(s): 1007
1 #include <cstdio> 2 #include <iostream> 3 #define N 105 4 5 using namespace std; 6 int a[N][N]; 7 int dp[N][N]; 8 int sum[N][N]; 9 10 int main() 11 { 12 int X; 13 int T, t; 14 int m, n; 15 16 scanf("%d", &T); 17 X = T; 18 while(T--) { 19 scanf("%d%d", &m, &n); 20 for(int i = 0; i < m; i++) { 21 for(int j = 0; j < n; j++) 22 scanf("%d", &a[i][j]); 23 } 24 25 for(int j = 0; j < n; j++) { 26 for(int i = 0; i < m; i++) { 27 if(i == 0) 28 sum[i][j] = a[i][j]; 29 else 30 sum[i][j] = a[i][j] + sum[i-1][j]; 31 } 32 } 33 for(int i = 0; i < m; i++) 34 dp[i][0] = sum[i][0]; 35 for(int j = 1; j < n; j++) { 36 for(int i = 0; i < m; i++) 37 { 38 dp[i][j] = 0-0xfffffff; 39 for(int k = 0; k < m; k++) 40 { 41 if(i >= k) { 42 t = dp[k][j-1] + sum[i][j] - sum[k][j] + a[k][j]; 43 } 44 else { 45 t = dp[k][j-1] + sum[k][j] - sum[i][j] + a[i][j]; 46 } 47 dp[i][j] = max(dp[i][j], t); 48 } 49 } 50 } 51 printf("Case #%d:\n", X-T); 52 printf("%d\n", dp[0][n-1]); 53 } 54 return 0; 55 }
标签:des c style class blog code
原文地址:http://www.cnblogs.com/sayeter/p/3736595.html