hdu1078FatMouse and Cheese

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1078

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int maxn=1010;
 6 int dp[maxn][maxn];
 7 int p[maxn][maxn];
 8 int n,k;
 9 int dir[4][2]={0,1,0,-1,1,0,-1,0};
10
11 int dfs(int x,int y)
12 {
13     int ans=0;
14     int xx,yy;
15     if(!dp[x][y])
16     {
17         for(int i=1;i<=k;i++)   //最多走k步
18         {
19             for(int j=0;j<4;j++)
20             {
21                  xx=x+dir[j][0]*i;
22                  yy=y+dir[j][1]*i;
23                 if(xx>=1&&yy>=1&&xx<=n&&yy<=n&&p[xx][yy]>p[x][y])
24                     ans=max(ans,dfs(xx,yy));
25             }
26         }
27         dp[x][y]=ans+p[x][y];
28     }
29     return dp[x][y];
30 }
31 int main()
32 {
33     while(scanf("%d%d",&n,&k)&&(n!=-1&&k!=-1))
34     {
35         for(int i=1;i<=n;i++)
36             for(int j=1;j<=n;j++)
37             scanf("%d",&p[i][j]);
38         memset(dp,0,sizeof(dp));
39         printf("%d\n",dfs(1,1));
40     }
41 }
时间: 2024-11-06 12:28:36

hdu1078FatMouse and Cheese的相关文章

[2016-03-28][HDU][1078][FatMouse and Cheese]

时间:2016-03-28 17:40:34 星期一 题目编号:[2016-03-28][HDU][1078][FatMouse and Cheese] #include <algorithm> #include <cstring> #include <cstdio> using namespace std; const int maxn = 100 + 10; int a[maxn][maxn]; int dp[maxn][maxn]; int n ,k; int d

记忆化搜索,FatMouse and Cheese

1.从gird[0][0]出发,每次的方向搜索一下,每次步数搜索一下 for(i=0; i<4; i++) { for(j=1; j<=k; j++) { int tx=x+d[i][0]*j; int ty=y+d[i][1]*j; if(tx>=0&&tx<n&&ty>=0&&ty<n&&grid[x][y]<grid[tx][ty]) { int temp=memSearch(tx,ty); i

HDU1078 FatMouse and Cheese 【内存搜索】

FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4966    Accepted Submission(s): 2035 Problem Description FatMouse has stored some cheese in a city. The city can be considere

UVA1001 Say Cheese

如果没有洞,那么任意两点的最短距离就是直线距离,洞里是瞬间的,所以看成一个点就行了(其实点也可以当作半径为0的洞来处理),洞到洞的最短距离都是圆心距离减去半径.剩下的就是完全图求单源最短路径,用不加堆优化的dijkstra就行了O(n^2). #include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 102; int x[maxn],y[maxn],z[maxn],r[maxn]; d

hdu 1078 FatMouse and Cheese

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5701    Accepted Submission(s): 2320 Problem Description FatMouse has stored some cheese in a city. The city can be considered as a square grid of

BZOJ2021: [Usaco2010 Jan]Cheese Towers

2021: [Usaco2010 Jan]Cheese Towers Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 184  Solved: 107[Submit][Status] Description Farmer John wants to save some blocks of his cows' delicious Wisconsin cheese varieties in his cellar for the coming winter.

HDU1078:FatMouse and Cheese(记忆化)

Problem Description 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 a

hdu1078 FatMouse and Cheese(记忆化搜索)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 Problem Description 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

UVA - 1001 Say Cheese(奶酪里的老鼠)(flod)

题意:无限大的奶酪里有n(0<=n<=100)个球形的洞.你的任务是帮助小老鼠A用最短的时间到达小老鼠O所在位置.奶酪里的移动速度为10秒一个单位,但是在洞里可以瞬间移动.洞和洞可以相交.输入n个球的位置和半径,以及A和O的坐标,求最短时间. 分析: 1.因为洞可以相交,所以在计算两点距离时要判断一下if(dist > num[i].r + num[j].r). 2.两球间的距离为球心间距离-两球半径,起点和终点不是球,可将半径设为0. #pragma comment(linker, &