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 ...
随机推荐
- Java NIO 文件通道 FileChannel 用法
FileChannel 提供了一种通过通道来访问文件的方式,它可以通过带参数 position(int) 方法定位到文件的任意位置开始进行操作,还能够将文件映射到直接内存,提高大文件的访问效率.本文将 ...
- dhcp分发地址以及静态路由设置
路由器R1配置: system-view [Huawei]sysname R1 [R1]user-interface console 0 [R1-ui-console0]idle-timeout 0 ...
- Go 的定时任务模块 Cron 使用
前言 新项目是Golang作为开发语言, 遇到了些新的坑, 也学到了新的知识, 收获颇丰 本章介绍在Go中使用Cron定时任务模块来实现逻辑 正文 在项目中, 我们往往需要定时执行一些逻辑, 举个例子 ...
- Go语言从入门到放弃(结构体常见的tag)
什么是tag Tag是结构体中某个字段别名, 可以定义多个, 空格分隔 type Student struct { Name string `ak:"av" bk:&quo ...
- 剑指offer 面试题6:从尾到头打印链表
题目描述 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList. 编程思想 从前往后遍历,将值存入栈中,然后打印栈中内容即可. 编程实现 /** * struct ListNode { * ...
- 天梯赛练习 L3-006 迎风一刀斩 (30分) 几何关系
题目分析: 对于给出的两个多边形是否可以组成一个矩形,这里我们分以下几种情况讨论 1.首先对于给出的两个多边形只有3-3,3-4,3-5,4-4才有可能组成一个矩形,并且两个多边形只可能是旋转90,1 ...
- jenkins + Ansible Plugin + ansi-color 让结果显示颜色
1 安装jenkins: 此处省略百余字...... 2 安装jenkins的插件: Ansible Plugin AnsiColor Plugin 3 设置job 内容 让ansible ...
- 【Oracle】Script to Collect DRM Information (drmdiag.sql) (文档 ID 1492990.1)
脚本对应如下: The following (drmdiag.sql) is a script to collect information related to DRM (Dyanamic Reso ...
- [Usaco2007 Jan]Balanced Lineup 飞盘比赛
题目描述 每天,农夫 John 的N(1 <= N <= 50,000)头牛总是按同一序列排队. 有一天, John 决定让一些牛们玩一场飞盘比赛. 他准备找一群在对列中为置连续的牛来进行 ...
- 小白的经典CNN复现(二):LeNet-5
小白的经典CNN复现(二):LeNet-5 各位看官大人久等啦!我胡汉三又回来辣(不是 最近因为到期末考试周,再加上老板临时给安排了个任务,其实LeNet-5的复现工作早都搞定了,结果没时间写这个博客 ...