hdu 1078 FatMouse and Cheese【dp】
题目链接: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;
}
hdu 1078 FatMouse and Cheese【dp】的更多相关文章
- HDU 1078 FatMouse and Cheese【记忆化搜索】
题意:给出n*n的二维矩阵,和k,老鼠每次最多走k步,问老鼠从起点(0,0)出发,能够得到的最大的数(即为将每走过一点的数都加起来的和最大)是多少 和上一题滑雪一样,搜索的方向再加一个循环 #incl ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
- HDU 1078 FatMouse and Cheese ( DP, DFS)
HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, k] 步, 从 ( ...
- hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)
pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...
- HDU 1078 FatMouse and Cheese(记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU - 1078 FatMouse and Cheese(记忆化+dfs)
FatMouse and Cheese FatMouse has stored some cheese in a city. The city can be considered as a squar ...
- HDU 1078 FatMouse and Cheese 记忆化搜索DP
直接爆搜肯定超时,除非你加了某种凡人不能想出来的剪枝...555 因为老鼠的路径上的点满足是递增的,所以满足一定的拓补关系,可以利用动态规划求解 但是复杂的拓补关系无法简单的用循环实现,所以直接采取记 ...
- HDU 1078 FatMouse and Cheese (记忆化搜索+dp)
详见代码 #include <iostream> #include <cstdio> #include <cstdlib> #include <memory. ...
- hdu 1078 FatMouse and Cheese 记忆化dp
只能横向或竖向走...一次横着竖着最多k步...不能转弯的.... 为毛我的500+ms才跑出来... #include<cstdio> #include<iostream> ...
随机推荐
- C#中的访问修饰符
1. 简述 private. protected. public. internal 修饰符的访问权限.private : 私有成员, 在类的内部才可以访问.protected : 保护成员,该类内部 ...
- 小二助手-react.js分块加载
小二助手在线演示地址:http://118.25.217.253:8000 账号test 密码123 小二助手是用material-ui开发的,感觉国内使用的人数不是特别多,所以创建了一个qq交流群 ...
- Material Design学习之 Bottom navigation
转载请注明出处:王亟亟的大牛之路 礼拜4一天由于事假没有去单位然后礼拜3由于生日也没写文章,今天一早上班就补一篇MD的内容.这一篇是关于颇有争议的Bottom navigation相关内容(主要是翻译 ...
- FastGUI for NGUI教程
原地址:http://blog.csdn.net/asd237241291/article/details/8499430 FastGUI是NGUI的一个扩展,所以必须要有NGUI才能使用.FastG ...
- Scapy基础学习之中的一个
关于Scapy Scapy的是一个强大的交互式数据包处理程序(使用python编写). 它可以伪造或者解码大量的网络协议数据包,可以发送.捕捉.匹配请求和回复包等等.它可以非常easy地处理一些典型操 ...
- lodash 工具库
lodash是一套工具库,内部封装了很多字符串.数组.对象等常见数据类型的处理函数. 1.lodash的引用 import _ from 'lodash' 用一个数组遍历来说明为什么要使用lodash ...
- 安卓File类汇总
File类 构造函数 參数 File(File dir,String name) File制定构造的新的File对象的路径.而String制定新的File名字 File(String path) St ...
- What most young programmers need to learn
In the past 7.5 years I have supervised over a dozen programming interns at Ronimo and have seen hun ...
- AspectJ 是什么
http://www.blogjava.net/hwpok/archive/2008/06/28/211312.html 1. 序 Aspect Oriented Programming (AOP)是 ...
- 【MyBatis学习01】宏观上把握MyBatis框架
今天开始学习mybatis框架,博客主要记录学习过程中的一些总结,如有错误之处,欢迎留言指正~先用mybatis的鸟鸟来镇个楼,咳咳~~ mybatis框架是一个持久层框架,是Apache下的顶级项目 ...