FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <= p < n and 0 <= q < n. At each grid location Fatmouse has hid between 0 and 100 blocks of cheese in a hole. Now he's going to enjoy his favorite food. 

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的更多相关文章

  1. FatMouse's Speed——J

    J. FatMouse's Speed FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  2. Hdu 1009 FatMouse' Trade

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  3. hdu 1078 FatMouse and Cheese

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  4. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. FatMouse' Trade_贪心

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  6. [题解]hdu 1009 FatMouse' Trade(贪心基础题)

    Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...

  7. 【HDU 1009】FatMouse' Trade

    题 Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the ware ...

  8. FatMouse的交易问题

    想按照某个值排序,用sort()函数,结果想了半天不知道用数组怎么解决,然后看了答案,才知道原来可以用struct,想想我真是笨死了.. 原题描述以及答案如下: Problem Description ...

  9. hdu 1009:FatMouse' Trade(贪心)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

随机推荐

  1. 原生redis命令

    一. redis-cli 连接 redis 进入redis安装目录 cd /usr/local/bin 进入redis客户端 ./redis-cli -p 6379 -h 用于指定 ip -p 用于指 ...

  2. 使用uiautomatorviewer报错Error obtaining UI hierarchy

    现象:使用uiautomatorviewer报错Error obtaining UI hierarchy 解决方法:经验证关闭appium,再重新获取,就不会报错     (python运行了app代 ...

  3. 通过DNSLOG回显验证漏洞

    通过DNSLOG回显验证漏洞 前言 实际渗透测试中,有些漏洞因为没有回显导致无法准确判断漏洞是否存在,可能导致渗透测试人员浪费大量精力在一个并不存在的漏洞上,因此为了验证一些无回显漏洞,可结合DNSl ...

  4. Nginx配置请求头

    最近发现一个问题: IOS访问后台接口是,总是application/json;charset=utf-8 但是后台接口只支持大写的UTF-8,修改了Nginx的请求头之后正常. proxy_set_ ...

  5. pip不是内部或外部命令解决方法

    问题 已经配置好Python环境,但是安装依赖时,出现pip不是内部或外部命令. 解决方法 找到pip.exe文件所在的目录,将所在路径配置到环境变量path中. 再次输入pip

  6. 使用正则表达式和urllib模块爬取最好大学排名信息

    题目 使用urllib模块编程实现爬取网站的大学排名. (网址:http://www.zuihaodaxue.cn/zuihaodaxuepaiming2016.html) (1)获取网站页面,分析代 ...

  7. maven仓库和镜像

    目录 简介 本地仓库 远程仓库 远程仓库的更新 远程仓库的认证 部署到远程仓库 快照版本 依赖解析 镜像 本文主要是针对<maven实战>书中关键知识点的学习记录,未免有纰漏或描述不到之处 ...

  8. kioptrixVM3

    简介 Vulnhub是一个提供各种漏洞环境的靶场平台. 个人学习目的:1,方便学习更多类型漏洞.2,为OSCP做打基础. 下载链接 https://www.vulnhub.com/entry/kiop ...

  9. ALV中layout布局控制详解

    参数的结构为SLIS_LAYOUT_ALV.结构中比较常用的字段如下: no_colhead      隐藏列标题          值为X或空 no_hotspot     headings不作为热 ...

  10. ABAP 多表联合查询

    inner join(等值连接) 只返回两个表中联结字段相等的行left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录right join(右联接) 返回包括右表中的所有记录 ...