标签:des style blog class c 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 <cstring> 3 #define max(x,y) (x >= y ? x : y) 4 #define MAX 102 5 #define INF (1<<30) 6 using namespace std; 7 8 int c[MAX][MAX]; 9 int dp[MAX][MAX]; /* 0 :left 1:behind 2 : right*/ 10 int ldp[MAX][MAX],rdp[MAX][MAX]; 11 int n,m; 12 13 void reset(){ 14 memset(dp,0,sizeof(dp)); 15 for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) dp[i][j] = dp[i][j] = dp[i][j] = -INF; 16 } 17 18 int main() 19 { 20 int t; 21 //freopen("data.txt","r",stdin); 22 scanf("%d",&t); 23 for(int z=1;z<=t;z++){ 24 scanf("%d %d",&m,&n); 25 memset(c,0,sizeof(c)); 26 reset(); 27 memcpy(ldp,dp,sizeof(dp)); 28 memcpy(rdp,dp,sizeof(dp)); 29 for(int j=1;j<=m;j++) for(int i=1;i<=n;i++) scanf("%d",&c[i][j]); 30 dp[1][1] = dp[1][1] = dp[1][1] = c[1][1]; 31 for(int j=1;j<=m;j++) dp[1][j] = dp[1][j-1]+c[1][j]; 32 for(int i=2;i<=n;i++){ 33 for(int j=1;j<=m;j++){ 34 dp[i][j] = dp[i-1][j] + c[i][j]; 35 } 36 ldp[i][1] = dp[i][1]; 37 for(int j=2;j<=m;j++){ 38 ldp[i][j] = max(ldp[i][j] , max(dp[i][j] , ldp[i][j-1]+c[i][j]) ); 39 } 40 rdp[i][m] = dp[i][m]; 41 for(int j=m-1;j>=1;j--){ 42 rdp[i][j] = max(rdp[i][j] , max(dp[i][j] , rdp[i][j+1]+c[i][j])); 43 } 44 45 for(int j=1;j<=m;j++) dp[i][j] = max(dp[i][j] , max(ldp[i][j] , rdp[i][j])); 46 } 47 printf("Case #%d:\n%d\n",z,dp[n][1]); 48 } 49 return 0; 50 }
百度之星2014资格赛 1004 - Labyrinth,布布扣,bubuko.com
标签:des style blog class c code
原文地址:http://www.cnblogs.com/sineatos/p/3737481.html