标签:with put php ati hdu splay contain stdio.h cep
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1078
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11361 Accepted Submission(s): 4829
1 #include<stdio.h>//hdu 1078 记忆化搜索 2 #include<string.h> 3 #define MAX(a,b) (a>b?a:b) 4 5 int n,k,dp[105][105],a[105][105],d[4][2] = {1,0,-1,0,0,1,0,-1}; 6 7 int dfs(int i,int j) 8 { 9 if(dp[i][j]) return dp[i][j]; 10 dp[i][j] = a[i][j]; 11 12 for(int t = 1; t<=k; t++) 13 for(int m = 0; m<4; m++) 14 { 15 int x = i+d[m][0]*t, y = j+d[m][1]*t; 16 if(x>=1 && x<=n && y>=1 && y<=n && a[x][y]>a[i][j]) 17 dp[i][j] = MAX(dp[i][j], a[i][j]+dfs(x,y)); 18 } 19 return dp[i][j]; 20 } 21 22 int main() 23 { 24 while(scanf("%d %d",&n,&k) && (n!=-1 || k!=-1)) 25 { 26 for(int i = 1; i<=n; i++) 27 for(int j = 1; j<=n; j++) 28 scanf("%d",&a[i][j]); 29 memset(dp,0,sizeof(dp)); 30 printf("%d\n",dfs(1,1)); 31 } 32 return 0; 33 }
HDU1078 FatMouse and Cheese —— 记忆化搜索
标签:with put php ati hdu splay contain stdio.h cep
原文地址:http://www.cnblogs.com/DOLFAMINGO/p/7631272.html