HDU 1078 FatMouse and Cheese 简单DP&记忆化搜索
来源:互联网 发布:茅场晶彦 知乎 编辑:程序博客网 时间:2024/05/21 15:35
题目链接:点击打开链接
题意:输入n,k,然后输入一个n*n的矩阵代表地图。矩阵中的每个元素代表这一个所包含的奶酪数量,小老鼠从(0,0)这个位置出发,只能水平或者竖直走,并且所走的位置必须必当前位置的奶酪多,并且每次走的步数不超过k步,求其能吃到的最大数量的奶酪数。
分析:我们从(0,0)出发深搜其能吃到的奶酪的数量,每次更新当前位置能吃到的最大值,最后得到的结果即为从(0,0)出发能得到的最大值。
#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <string>#include <vector>#include <deque>#include <list>#include <set>#include <map>#include <stack>#include <queue>#include <cctype>#include <numeric>#include <iomanip>#include <bitset>#include <sstream>#include <fstream>#define debug "output for debug\n"#define pi (acos(-1.0))#define eps (1e-8)#define inf 0x3f3f3f3f#define ll long long int#define lson l , m , rt << 1#define rson m + 1 , r , rt << 1 | 1using namespace std;const int mod = 1000000007;const int Max = 50005;int mp[105][105];int dp[205][205];int n,k;int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};int dfs(int x,int y){ if(dp[x][y]>0) return dp[x][y]; int tmp,ans=0; for(int i=0;i<4;i++) { for(int j=1;j<=k;j++) { int xx=dir[i][0]*j+x; int yy=dir[i][1]*j+y; if(xx>=0&&xx<n&&yy>=0&&yy<n&&mp[xx][yy]>mp[x][y]) { tmp=dfs(xx,yy); ans=max(ans,tmp); } } } dp[x][y]=ans+mp[x][y]; return dp[x][y];}int main(){ while(~scanf("%d%d",&n,&k)) { if(n==-1||k==-1) break; memset(mp,0,sizeof mp); memset(dp,0,sizeof dp); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { scanf("%d",&mp[i][j]); } } printf("%d\n",dfs(0,0)); } return 0;}
0 0
- HDU 1078 FatMouse and Cheese 简单DP&记忆化搜索
- hdu 1078 FatMouse and Cheese(dp 记忆化搜索)
- hdu(1078) FatMouse and Cheese (记忆化搜索+dp)
- !HDU 1078 FatMouse and Cheese-dp-(记忆化搜索)
- HDU 1078 FatMouse and Cheese 记忆化搜索模板 dp
- [HDU 1078 ] FatMouse and Cheese [ dp 记忆化搜索 ]
- hdu-1078 FatMouse and Cheese (and) 滑雪问题(记忆化搜索+简单dp)
- hdu-1078 FatMouse and Cheese (and) 滑雪问题(记忆化搜索+简单dp)
- HDU 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(记忆化搜索)
- hdu 1078 FatMouse and Cheese(记忆化搜索)
- hdu 1078 FatMouse and Cheese(记忆化搜索)
- HDU 1078 FatMouse and Cheese(记忆化搜索)
- Android WebView使用笔记
- 设计模式之适配器模式
- codevs1099 字串变换 string黑科技+队列
- POJ 1651 Multiplication Puzzle (矩阵连乘)
- Open XML操作Excel导入数据
- HDU 1078 FatMouse and Cheese 简单DP&记忆化搜索
- MyBatis入门04-实现关联表查询
- Serializable 和 Parcelable 区别
- 安卓4.4限制外置SD卡写入权限的破解方法
- golang开发环境mac下编译linux环境文件
- 关于字符编码
- URL
- nagios监控mysql
- VS中lib和dll的使用