HDU1078 FatMouse and Cheese [记忆化搜索DFS]
来源:互联网 发布:高级编程语言就业前景 编辑:程序博客网 时间:2024/05/29 11:09
N X N 的矩阵中, 一直老鼠每次最多可以走K步,走到的位置只能比前一个位置大,并且获得那里的价值,
问最大价值是多少;
在dfs中额外加一个判定就可以了,
然后每一步都取最大值就可以了
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int n,k,dp[155][155],a[155][155];int dir[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};int check(int x,int y){ if(x<1 || y<1 || x>n || y>n) return 1; return 0;}int dfs(int x,int y){ int i,j,l,ans = 0; if(!dp[x][y]) { for(i = 1; i<=k; i++) { for(j = 0; j<4; j++) { int nx = x+dir[j][0]*i; int ny = y+dir[j][1]*i; if(check(nx,ny)) continue; if(a[nx][ny]>a[x][y]) ans = max(ans,dfs(nx,ny)); } } dp[x][y] = ans+a[x][y]; } return dp[x][y];}int main(){ int i,j; while(~scanf("%d%d",&n,&k),n>0&&k>0) { for(i = 1; i<=n; i++) for(j = 1; j<=n; j++) scanf("%d",&a[i][j]); memset(dp,0,sizeof(dp)); printf("%d\n",dfs(1,1)); } return 0;}
0 0
- hdu1078+FatMouse and Cheese+DFS+记忆化搜索
- HDU1078 FatMouse and Cheese [记忆化搜索DFS]
- HDU1078 FatMouse and Cheese(DFS记忆化搜索)
- hdu1078 FatMouse and Cheese(记忆化搜索)
- HDU1078 FatMouse and Cheese 【记忆化搜索】
- hdu1078 FatMouse and Cheese 记忆化搜索
- HDU1078 FatMouse and Cheese记忆化搜索
- hdu1078 fatmouse and cheese 记忆化搜索
- hdu1078 FatMouse and Cheese【记忆化搜索】
- hdu1078 FatMouse and Cheese(记忆化搜索)
- hdu1078 FatMouse and Cheese(记忆化搜索)
- hdu1078 FatMouse and Cheese —— 记忆化搜索
- HDU1078:FatMouse and Cheese(记忆化 dp+搜索) (P)
- HDU1078 FatMouse and Cheese DP(记忆化搜索)
- hdu1078 FatMouse and Cheese 搜索dfs&dp
- HDU1078:FatMouse and Cheese(记忆化)
- HDU1078:FatMouse and Cheese(记忆化)
- 记忆化搜索:HDU1078-FatMouse and Cheese(记忆化搜索)
- 归并排序
- 排序和正则表达式的应用
- 快速排序
- 抽屉效果
- 冒泡排序
- HDU1078 FatMouse and Cheese [记忆化搜索DFS]
- 动态规划解回文
- 选择排序
- 查找 1
- Asp.net MVC3使用Reporting Services生成PDF解决Web在线打印
- Poj 3461 Oulipo
- 统计排序
- 理解矩阵
- [读书笔记]《Android开发艺术探索》第二章笔记