标签:des style blog class code java
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8600 Accepted Submission(s): 3032
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #define maxn -0x3f3f3f3f 5 int dp[21][1001],sum[21][1001]; 6 int max(int a ,int b){ 7 if(a>b) return a; 8 return b; 9 } 10 int main() 11 { 12 int c,n,m,k,i,j; 13 scanf("%d",&c); 14 while(c--){ 15 scanf("%d%d",&n,&m); 16 for(i=1; i<=n;i++){ 17 for(j=1;j<=m;j++){ 18 scanf("%d",&dp[i][j]); 19 } 20 } 21 // memset(sum,0,sizeof(sum)); 22 //对边缘进行必要地初始化.... 23 for(i=0;i<=n;i++) sum[i][0]=maxn; 24 for(i=1;i<=m;i++) sum[0][i]=maxn; 25 sum[1][0]=sum[0][1]=0; 26 for( i=1 ; i<=n ; i++ ){ 27 for( j=1 ; j<=m ; j++ ){ 28 //选择是向下还是向右进行行走....... 29 sum[i][j]= max( sum[i-1][j],sum[i][j-1] )+ dp[i][j]; 30 //对于向右行走,该怎么走....... 31 int ks=2; 32 while(j>=ks){ 33 if(j%ks==0) //比较它们的倍数 34 sum[i][j] = max( sum[i][j] , sum[i][j/ks]+dp[i][j] ) ; 35 ks++; //所有的倍数..... 36 } 37 } 38 } 39 printf("%d\n",sum[n][m]); 40 } 41 return 0; 42 }
HDUOJ----2571(命运)(简单动态规划),布布扣,bubuko.com
标签:des style blog class code java
原文地址:http://www.cnblogs.com/gongxijun/p/3720061.html