hdu 1078 FatMouse and Cheese (dp+dfs)
来源:互联网 发布:青少年编程培训班 编辑:程序博客网 时间:2024/05/18 03:52
题意:
老鼠从(0,0)点出发,每次老鼠最多移动k步,且移动过去的下一点的奶酪要比当前点多。
思路:
第一次把dp和dfs相结合,刚开始忘了标记走过的路结果超时了。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int n,k;int ma[105][105],dp[105][105];int dx[4]={1,-1,0,0};int dy[4]={0,0,1,-1};int dfs(int x,int y){int mx=0,te,xx,yy;if(!dp[x][y]){for(int co=1;co<=k;co++){for(int i=0;i<4;i++){xx=x+dx[i]*co;yy=y+dy[i]*co;if(xx>=0&&yy>=0&&xx<n&&yy<n&&ma[xx][yy]>ma[x][y]){te=dfs(xx,yy);mx=max(mx,te);}}} dp[x][y]=mx+ma[x][y];}return dp[x][y];}int main(){while(scanf("%d%d",&n,&k)){if(n==-1&&k==-1) break;memset(dp,0,sizeof(dp));for(int i=0;i<n;i++)for(int j=0;j<n;j++)scanf("%d",&ma[i][j]);printf("%d\n",dfs(0,0));}return 0;}
阅读全文
0 0
- hdu 1078(dfs+dp)FatMouse and Cheese
- hdu 1078 FatMouse and Cheese【dfs+dp】
- hdu 1078 FatMouse and Cheese (dp+dfs)
- 1078 FatMouse and Cheese DFS+DP
- hdu 1078 FatMouse and Cheese(dfs)
- 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】
- DP-HDU-1078-FatMouse and Cheese
- HDU - 1078----FatMouse and Cheese(dp制表)
- hdu FatMouse and Cheese(dp)
- HDU 1078 FatMouse and Cheese (dfs + dp记忆化搜索)
- HDOJ 1078 FatMouse and Cheese (DFS+DP)
- HDU1078 FatMouse and Cheese(DFS+DP)
- hdu1078 FatMouse and Cheese 搜索dfs&dp
- FatMouse and Cheese 【dp思想的dfs】
- 顺序栈,数组存储栈元素(C++)
- UIView动画只显示结果UIview动画闪现
- C程序设计基础——二维数组的最大值
- 关于Android Recyclerview隐藏item的所在区域显示大空白问题的解决方案
- 幸运抽奖_学习笔记
- hdu 1078 FatMouse and Cheese (dp+dfs)
- Spring定时任务的几种实现 附实例
- LunarConsole使用
- 设计师如何培养良好的设计思维?
- Ubuntu 16.04.1搭建mantis服务器(基于php7.0)
- ajax 编辑保存table
- STL学习感悟(一)
- RocketMQ Quick Start
- 不能错过的Sketch实用新技巧和资源集锦