(Memory Search) Fatmouse and Cheese (HDU 1078)

Source: Internet
Author: User

Main topic: to N*n map, the mouse initial position in (0,0), it each walk or walk sideways or vertical walk, each time up to a maximum of K unit length, and the value of the end point must be greater than the weight of the previous foothold, to find the ultimate maximum weight can be obtained (the topic is easy to understand the wrong test instructions, the road friend careful)

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;#defineMet (A, B) (Memset (A,b,sizeof (a)))#defineN 110#defineINF 0XFFFFFFintA[n][n], dp[n][n];intdir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};intDasointNintKintXinty) {    if(!Dp[x][y]) {        intans=0;  for(intI=1; i<=k; i++)        {            inttemp=0;  for(intj=0; j<4; J + +)            {                intNX = x + dir[j][0]*i; intNY = y + dir[j][1]*i; if(nx>=1&& nx<=n && ny>=1&& ny<=n && a[nx][ny]>A[x][y]) {Temp=Max (temp, DFS (n, K, NX, NY)); }} ans=max (ans, temp); } Dp[x][y]= ans +A[x][y]; }    returndp[x][y];}intMain () {intN, K;  while(SCANF ("%d%d", &n, &k), n!=-1|| k!=-1)    {        intI, J; Met (A,0); Met (DP,0);  for(i=1; i<=n; i++)         for(j=1; j<=n; J + +) scanf ("%d", &A[i][j]); printf ("%d\n", DFS (n, K,1,1)); }    return 0;}

http://acm.hdu.edu.cn/showproblem.php?pid=1078

  
 Fatmouse and CheeseTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 7774 Accepted Submission (s): 3221


problem Descriptionfatmouse have stored some cheese in a city. The city can being considered as a square grid of dimension N:each grid location are labelled (P,Q) where 0 <= p < n an D 0 <= Q < n. At each of the grid location Fatmouse have hid between 0 and blocks of cheese in a hole. Now he's going to enjoy him favorite food.

Fatmouse begins by standing on location (0,0). He eats up the cheese where he stands and then runs either horizontally or vertically to another location. The problem is a there are a super Cat named Top Killer sitting near his hole, so each time he can run at most K locatio NS to get into the hole before being caught by Top Killer. What's worse--after eating up the cheese at one location, Fatmouse gets fatter. So-in order-gain enough-he-has-to-run to-a location which had more blocks of cheese than thos E 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 CA N Eat before being unable to move.  
InputThere is several test cases. Each test case consists of

a line containing 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,n-1), and so on.
The input ends with a pair of-1 ' s. 
OutputThe For all test case is output in a line, the single integer giving the number of blocks of cheese collected. 
Sample Input3 2 510 612 7-1-1 
Sample OutputPanax Notoginseng 
SourceZhejiang University Training Contest 2001

(Memory Search) Fatmouse and Cheese (HDU 1078)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.