hdu 1078 FatMouse and Cheese【dp】
来源:互联网 发布:有没有淘宝内部优惠券 编辑:程序博客网 时间:2024/05/01 01:51
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078
题意:每次只能走 横着或竖着的 1~k 个格子,求最多能吃到的奶酪。
代码:
#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include <string>#include <functional>#include <iterator>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <set>#include <map>#include <list>#include <bitset>#include <sstream>#include <iomanip>#include <fstream>#include <iostream>#include <cmath>#include <cstring>#include <cstdio>#include <time.h>#include <ctype.h>#include <string.h>#include <assert.h>using namespace std;int n, k;int a[110][110], dp[110][110];int dir[4][2] = { { 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 } };bool is_ok(int x, int y){ if (x < 0 || x >= n || y < 0 || y >= n) return false; return true;}int res(int x, int y){ int sum = 0,tmp = 0; if (!dp[x][y]) { for (int i = 1; i <= k; i++) { for (int j = 0; j < 4; j++) { int xx = x + dir[j][0] * i; int yy = y + dir[j][1] * i; if (is_ok(xx,yy) && a[xx][yy] > a[x][y]) { sum = res(xx, yy); tmp = max(tmp, sum); } } } dp[x][y] = tmp + a[x][y]; } return dp[x][y];}int main(){ while (scanf("%d %d", &n,&k) != EOF) { if (n == -1 && k == -1) break; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%d",&a[i][j]); memset(dp, 0, sizeof(dp)); printf("%d\n", res(0,0)); } return 0;}
0 0
- hdu 1078 FatMouse and Cheese (搜索+dp)
- hdu 1078(dfs+dp)FatMouse and Cheese
- 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 1078 FatMouse and Cheese【dfs+dp】
- hdu 1078 FatMouse and Cheese (dp+dfs)
- 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
- Spring Security的配置使用
- iOS中几种数据持久化方案:我要永远地记住你!
- 国外旋转楼梯sketchup建模教程h
- java.io.file 各种文件操作
- [Android5 系列—] 4. Android 3D 入门
- hdu 1078 FatMouse and Cheese【dp】
- ios 自定义cell中有textField,点击textField时,防止键盘挡住textField
- Hadoop参数汇总
- 内核抢占和schedule()函数的分析
- Zookeeper启动过程
- PCRE正则表达式(零)环境搭建
- Jquery获取未选中的checkbox
- PHP版蚂蚁爬杆路径算法
- LoaderManager使用详解(四)---实例:AppListLoader