FatMouse and CheeseI - I
FatMouse begins by standing at location (0,0). He eats up the cheese where he stands and then runs either horizontally or vertically to another location. The problem is that there is a super Cat named Top Killer sitting near his hole, so each time he can run at most k locations to get into the hole before being caught by Top Killer. What is worse -- after eating up the cheese at one location, FatMouse gets fatter. So in order to gain enough energy for his next run, he has to run to a location which have more blocks of cheese than those that were at the current hole.
Given n, k, and the number of blocks of cheese at each grid location, compute the maximum amount of cheese FatMouse can eat before being unable to move.
InputThere are several test cases. Each test case consists of
a line containing two integers between 1 and 100: n and k
n lines, each with n numbers: the first line contains the number of blocks of cheese at locations (0,0) (0,1) ... (0,n-1); the next line contains the number of blocks of cheese at locations (1,0), (1,1), ... (1,n-1), and so on.
The input ends with a pair of -1's.
OutputFor each test case output in a line the single integer giving the number of blocks of cheese collected.
Sample Input
3 1
1 2 5
10 11 6
12 12 7
-1 -1
Sample Output
37
1 #include<stdio.h>
2 #include<string.h>
3 #include<queue>
4 #include<set>
5 #include<iostream>
6 #include<map>
7 #include<stack>
8 #include<cmath>
9 #include<algorithm>
10 #define ll long long
11 using namespace std;
12 int n,k;
13 int f[4][2]={1,0,0,1,-1,0,0,-1};
14 int dp[1000][1000],e[1000][1000];
15 int dfs(int x,int y)
16 {
17 if(dp[x][y]) return dp[x][y];
18 for(int i=0;i<4;i++)
19 {
20 for(int j=1;j<=k;j++)
21 {
22 int tx=x+j*f[i][0];
23 int ty=y+j*f[i][1];
24 if(tx>=0&&ty>=0&&tx<n&&ty<n&&e[tx][ty]>e[x][y])
25 {
26 dp[x][y]=max(dfs(tx,ty)+e[tx][ty],dp[x][y]);
27 }
28 }
29 }
30 return dp[x][y];
31 }
32 int main()
33 {
34 while(~scanf("%d%d",&n,&k)&&(n+k)!=-2)
35 {
36 memset(dp,0,sizeof(dp));
37 for(int i=0;i<n;i++)
38 for(int j=0;j<n;j++)
39 scanf("%d",&e[i][j]);
40 printf("%d\n",dfs(0,0)+e[0][0]);
41 }
42 }
FatMouse and CheeseI - I的更多相关文章
- FatMouse's Speed——J
J. FatMouse's Speed FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- Hdu 1009 FatMouse' Trade
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1078 FatMouse and Cheese
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- FatMouse' Trade_贪心
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- [题解]hdu 1009 FatMouse' Trade(贪心基础题)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- 【HDU 1009】FatMouse' Trade
题 Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the ware ...
- FatMouse的交易问题
想按照某个值排序,用sort()函数,结果想了半天不知道用数组怎么解决,然后看了答案,才知道原来可以用struct,想想我真是笨死了.. 原题描述以及答案如下: Problem Description ...
- hdu 1009:FatMouse' Trade(贪心)
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- (开源项目)abattoir unity游戏
(开源项目)abattoir unity游戏 欢迎各位的改进和提议! 名称: abattoir(角斗场) 版本: v1.0 作者: N-n-N(笔者) 简介: 添加娱乐(冲撞)模式和普通(一般)模式 ...
- ORA-28001: the password has expired解决方法
Oracle提示错误消息ORA-28001: the password has expired,是由于Oracle11G的新特性所致, Oracle11G创建用户时缺省密码过期限制是180天(即6个月 ...
- yolov5实战之皮卡丘检测
前言 从接触深度学习开始一直都做的是人脸识别,基本上也一直都在用mxnet. 记得之前在刚接触的时候看到博客中写到,深度学习分三个层次,第一个层次是分类,第二个层次是检测,第三个层次是分割.人脸识别算 ...
- Linux复制某个目录下结构
Linux复制某个目录下结构 结合tree命令把当前目录下的文件夹路径存储到document.txt文件,然后再使用mkdir命令把document.txt文件下的目录输入创建: tree -fid ...
- xtrabackup_binlog_info
文件保存了备份结束时刻binlog的名称和位置
- LeetCode993. 二叉树的堂兄弟节点
题目 1 class Solution { 2 public: 3 TreeNode* r1;TreeNode* r2; 4 bool isCousins(TreeNode* root, int x, ...
- cmd的终结工具cmder
常用快捷键 win+alt+t 打开任务设置窗口 win+alt+k 打开快捷键设置窗口 自定义屏幕分割窗口快捷键: ctl+shift+s 水平按50%比例分割 ctl+shift+v 垂直按50 ...
- 图像分割论文 | DRN膨胀残差网络 | CVPR2017
文章转自:同作者个人微信公众号[机器学习炼丹术].欢迎交流沟通,共同进步,作者微信:cyx645016617 论文名称:'Dilated Residual Networks' 论文链接:https:/ ...
- [Usaco2008 Nov]Buying Hay 购买干草
题目描述 约翰的干草库存已经告罄,他打算为奶牛们采购H(1≤H≤50000)磅干草,他知道N(1≤N≤100)个干草公司,现在用1到N给它们编号.第i个公司卖的干草包重量为Pi(1≤Pi≤5000)磅 ...
- USB限流IC,输入5V,输出5V,最大3A限流
USB限流芯片,5V输入,输出5V电压,限流值可以通过外围电阻进行调节,PWCHIP产品中可在限流范围0.4A-4.8A,并具有过压关闭保护功能. 过压关闭保护: 如芯片:PW1555,USB我们一半 ...