HDU 1078 FatMouse and Cheese (记忆化搜索)
来源:互联网 发布:骚男淘宝外设店 编辑:程序博客网 时间:2024/05/21 22:25
#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<sstream>using namespace std;typedef long long LL;const int M = 10000;const int INF = 0x3f3f3f3f;int n, k;int dir[][2] = { 1,0,-1,0,0,1,0,-1 };int dp[105][105];int ans;int mp[105][105];bool vis[105][105];int dfs(int x, int y){int res = 0;int sum = 0;if (!vis[x][y]){vis[x][y] = 1;//dp[x][y] += mp[x][y];for (int i = 1; i <= k; ++i) //最多走K步{for (int j = 0; j < 4; ++j) //每个方向i步 遍历{int xx = x + dir[j][0] * i; int yy = y + dir[j][1] * i;if (xx < 0 || xx >= n || yy < 0 || yy >= n){continue;}if (mp[xx][yy] > mp[x][y]){sum = dfs(xx, yy); }res = max(res, sum); //在当前(x,y)开始 所能走出的最大值}}dp[x][y] = res + mp[x][y];}return dp[x][y];}int main(){while (~scanf("%d%d", &n, &k) && (n + k != -2)){for (int i = 0; i < n; ++i){for (int j = 0; j < n; ++j){scanf("%d", &mp[i][j]);}}memset(dp, 0, sizeof(dp));memset(vis, 0, sizeof(vis));cout << dfs(0,0) << endl;}return 0;}
0 0
- 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 (dfs+记忆化搜索)
- hdu-1078 FatMouse and Cheese(记忆化搜索)
- FatMouse and Cheese (hdu 1078 记忆化搜索)
- !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 记忆化搜索
- hdu 1078 FatMouse and Cheese(dp 记忆化搜索)
- hdu 1078 FatMouse and Cheese(记忆化搜索)
- hdu 1078 FatMouse and Cheese 记忆化搜索
- HDU 1078 FatMouse and Cheese(记忆化搜索)
- Java Enum(枚举类型)的几种使用方法
- JABC编程
- 二维费用背包codevs1669运输装备
- nodejs微信开发--设置自定义菜单
- Qt:QT中PRO文件写法的详细介绍
- HDU 1078 FatMouse and Cheese (记忆化搜索)
- IOS开发之----让UILabel 垂直方向顶端对齐的代码
- int型转二进制,八进制,十六进制查表法
- CLR 无法从 COM 上下文 0x208f68 转换为 COM 上下文 0x2090d8,这种状态已持续 60 秒
- 151019总结
- iOS 视图控件颜色渲染
- LeetCode 10: Regular Expression Matching
- centos下安装memcache
- 第十三周第一天