Fatmouse and cheese
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 3509 accepted submission (s): 1388 problem descriptionfatmouse has stored some cheese in a city. the city can be considered as a square grid of dimension n: each grid location is labeled (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
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, 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 11 2 510 11 612 12 7-1 -1
Sample output
37
Q: The mouse steals food. There are N * n square arrays. Each grid contains a certain amount of food. The mouse can only take a maximum of K Steps horizontally or vertically at a time, each time you have to go through a grid with more food than the current one, ask how much food you can eat at most. PS: I can't understand English.
Idea: memory-based search is almost the same as that of skiing, because K steps can be taken.
# Include <iostream> # include <cstdio> # include <cstring> # define maxn 105 using namespace STD; int n, m, K, ans; int MP [maxn] [maxn]; int DP [maxn] [maxn]; int DX [] = {-1, 1, 0, 0}; int dy [] = {0, 0, -1,1}; int DFS (int x, int y) {If (DP [x] [Y]) return DP [x] [Y]; // int I, j, T, TX, Ty, MA = 0; for (I = 1; I <= K; I ++) {for (j = 0; j <4; j ++) {Tx = x + I * DX [J]; ty = Y + I * dy [J]; if (TX> = 1 & TX <= N & ty> = 1 & ty <= N & MP [TX] [ty]> MP [x] [y ]) {T = DFS (TX, Ty); If (MA <t) Ma = T ;}}} DP [x] [Y] = MA + MP [x] [Y]; return DP [x] [Y];} int main () {int I, j, T; while (scanf ("% d", & N, & K) {If (n =-1 & K =-1) break; memset (DP, 0, sizeof (DP); for (I = 1; I <= N; I ++) {for (j = 1; j <= N; j ++) {scanf ("% d", & MP [I] [J]) ;}} printf ("% d \ n", DFS () ;}return 0 ;}