hdu 1078 FatMouse and Cheese_记忆搜索
来源:互联网 发布:软件界面设计要求 编辑:程序博客网 时间:2024/05/29 13:36
做这类型的搜索比较少,看懂题意花了半天
题意:给你个n*n的图,老鼠一次最远走k步,老鼠起初在(0,0),每次偷吃的东西必须比之前偷吃的要大。
#include<iostream>#include<cstdio>using namespace std;#define N 110int map[N][N],dp[N][N];int n,k;int dir[][2]={{1,0},{0,1},{-1,0},{0,-1}};int solve(int x,int y){ int i,j,max=0,sum,tx,ty; if(dp[x][y]) return dp[x][y]; for(i=0;i<4;i++) for(j=1;j<=k;j++) { tx=x+dir[i][0]*j; ty=y+dir[i][1]*j; if(tx>=0&&tx<n&&ty>=0&&ty<n&&map[tx][ty]>map[x][y]) { sum=solve(tx,ty); if(sum>max) max=sum; } } return dp[x][y]=max+map[x][y];}int main(){ int i,j; while(scanf("%d%d",&n,&k)!=EOF&&(n+k!=-2)) { for(i=0;i<n;i++) for(j=0;j<n;j++) { scanf("%d",&map[i][j]); dp[i][j]=0; } printf("%d\n",solve(0,0)); } return 0;}
- hdu 1078 FatMouse and Cheese_记忆搜索
- hdu 1078 fatmouse and cheese 记忆化搜索
- hdu 1078 FatMouse and Cheese(深搜----记忆化搜索)
- HDU 1078 FatMouse and Cheese(记忆搜索)
- hdu 1078 FatMouse and Cheese(dp 记忆化搜索)
- hdu 1078 FatMouse and Cheese(记忆化搜索)
- hdu 1078 FatMouse and Cheese 记忆化搜索
- hdu 1078 FatMouse and Cheese (记忆化搜索 )
- HDU 1078 FatMouse and Cheese(记忆化搜索)
- HDU--1078 -- FatMouse and Cheese [记忆搜索] [DFS]
- hdu 题目1078FatMouse and Cheese(记忆搜索)
- hdu(1078) FatMouse and Cheese (记忆化搜索+dp)
- hdu 1078 FatMouse and Cheese(记忆化搜索)
- hdu 1078 FatMouse and Cheese(记忆化搜索)
- HDU 1078 FatMouse and Cheese(记忆化搜索)
- hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)
- hdu-1078 FatMouse and Cheese(记忆化搜索)
- 【记忆化搜索】HDU-1078 FatMouse and Cheese
- 放假了,A题了!!!
- android 把本地图片写入到SD卡其他目录中
- HDU-1712-ACboy needs your help
- UVA 11107(Life Forms-后缀数组+二分)
- HDU-2159-FATE
- hdu 1078 FatMouse and Cheese_记忆搜索
- HDU-2191-悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
- 买不到的数目 蓝桥杯决赛
- 左旋字符串
- HDU-2546-饭卡
- flex复选框和下拉列表
- [时间投资法]第一章-为什么高效管理时间这样难
- How should i explain Dynamic Programming to a 4-year-old?
- NSString 为什么要使用copy,而不是retain?