HDU 1078 FatMouse and Cheese
来源:互联网 发布:linux域控 编辑:程序博客网 时间:2024/05/02 01:05
题目分析
这道题跟poj上面的滑雪是一样的题目,但是这道题改变的地方有,每一次可以移动k步,而不是一步,很明显多加一重循环就可以了,同时那道题求得是递减的长度,这道题求得是递增得到的最大数量的奶酪。直接记忆化搜索就可以了。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 105;int maze[maxn][maxn];int dp[maxn][maxn];int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};int n,k;bool judge(int x,int y){ if(x < 1 || x > n || y < 1 || y > n) return false; return true;}int solve(int x,int y,int k){ if(dp[x][y]) return dp[x][y]; int ret = 0; for(int i = 0; i < 4; i++) { for(int j = 1; j <= k; j++) { int xx = x + j*dir[i][0]; int yy = y + j*dir[i][1]; if(!judge(xx,yy)) break; if(maze[xx][yy] > maze[x][y]) ret = max(ret, solve(xx,yy,k)); } } dp[x][y] = ret+maze[x][y]; return dp[x][y];}int main(){ while(scanf("%d%d", &n, &k) != EOF) { if(n == -1 && k == -1) break; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) scanf("%d", &maze[i][j]); memset(dp,0,sizeof(dp)); printf("%d\n", solve(1,1,k)); } return 0;}
0 0
- 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
- 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
- java redis demo关于List<Integer>,List<String>
- RecyclerView刷新
- windows的20%带宽限制的误区
- 手把手教你使用Git
- Linux开发工具(gcc,gdb,make,shell)——linux中静态库和动态库的区别(三)
- HDU 1078 FatMouse and Cheese
- Square
- bootstrap学习笔记-导航和导航条
- 指针形参
- CrackingtheCodeInterview之递归和动态规划
- MyBatis快速入门_1
- 大小和尺寸的概念
- Android Studio实现代码混淆
- Linux gcc编译器常用命令和使用