HDU 1078FatMouse and Cheese(记忆化搜索)
来源:互联网 发布:linux 中文man手册 编辑:程序博客网 时间:2024/06/18 14:35
题意:老鼠从(0,0)点走,每次最多可以走k步(只能水平或垂直地走),且下一个点的价值比当前点的价值大。求他得到的价值最大为多少。
#include <iostream>#include <queue>#include <stdio.h>#include <math.h>#include <algorithm>#include <vector>#include <map>#include <set>#include <string.h>#include <string>using namespace std;#define maxn 105#define inff 0x7FFFFFFint maz[maxn][maxn],dp[maxn][maxn];int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};int n,k;int dfs(int x,int y){ int maxx=0; if(!dp[x][y]) { for(int i=1;i<=k;i++) { for(int j=0;j<4;j++) { int tx=x+dir[j][0]*i; int ty=y+dir[j][1]*i; if(tx<=n&&tx>=1&&ty>=1&&ty<=n&&maz[x][y]<maz[tx][ty]) { int temp=dfs(tx,ty); maxx=max(temp,maxx); } } } dp[x][y]=maxx+maz[x][y]; } return dp[x][y];}int main(){ int i,j; while(scanf("%d%d",&n,&k)!=EOF) { if(n==-1&&k==-1) return 0; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { scanf("%d",&maz[i][j]); } } memset(dp,0,sizeof dp); int ans=dfs(1,1); cout<<ans<<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 (记忆化搜索 )
- 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 (dfs+记忆化搜索)
- hdu-1078 FatMouse and Cheese(记忆化搜索)
- 【记忆化搜索】HDU-1078 FatMouse and Cheese
- HDU--1078--FatMouse and Cheese--记忆化搜索
- FatMouse and Cheese (hdu 1078 记忆化搜索)
- P - FatMouse and Cheese HDU 1078 ( 记忆化搜索 )
- hdu 1078 FatMouse and Cheese(记忆化搜索)
- hdu 5490 Simple Matrix 递推公式+逆元+组合数
- 正则表达式(Regular Expression)教程
- 【Linux 移植 】——4、移植 u-boot-2012.04.01 之 支持NAND启动
- Linux内核的构建过程----Linux内核剖析(五)
- 前向定义导致 程序编译出现"field has incomplete type"问题的解决
- HDU 1078FatMouse and Cheese(记忆化搜索)
- IOS中定时器NSTimer的开启与关闭
- hdu1257最少拦截系统(贪心)
- iOS面试问题
- 【Leetcode算法】- Rotate Array
- Java 重写(Override)与重载(Overload)
- iOS编程------初级数据持久化/沙盒机制/NSFileManager/简单对象写入文件/复杂对象写入文件
- Three.js讲解以及WEBGL实例
- R包的安装