题目大意:
 

给n*n地图,老鼠初始位置在(0,0),它每次行走要么横着走要么竖着走,每次最多可以走出k个单位长度,且落脚点的权值必须比上一个落脚点的权值大,求最终可以获得的最大权值

 

(题目很容易会理解错题意,道友小心)

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <cmath>
  6. using namespace std;
  7.  
  8. #define met(a,b) (memset(a,b,sizeof(a)))
  9. #define N 110
  10. #define INF 0xffffff
  11.  
  12. int a[N][N], dp[N][N];
  13. int dir[][]={{-,},{,},{,-},{,}};
  14.  
  15. int DFS(int n, int k, int x, int y)
  16. {
  17. if(!dp[x][y])
  18. {
  19. int ans=;
  20.  
  21. for(int i=; i<=k; i++)
  22. {
  23. int temp=;
  24.  
  25. for(int j=; j<; j++)
  26. {
  27. int nx = x + dir[j][]*i;
  28. int ny = y + dir[j][]*i;
  29.  
  30. if(nx>= && nx<=n && ny>= && ny<=n && a[nx][ny]>a[x][y])
  31. {
  32. temp = max(temp, DFS(n, k, nx, ny));
  33. }
  34. }
  35. ans = max(ans, temp);
  36. }
  37. dp[x][y] = ans + a[x][y];
  38. }
  39. return dp[x][y];
  40. }
  41.  
  42. int main()
  43. {
  44. int n, k;
  45.  
  46. while(scanf("%d%d", &n, &k), n!=-||k!=-)
  47. {
  48. int i, j;
  49.  
  50. met(a, );
  51. met(dp, );
  52.  
  53. for(i=; i<=n; i++)
  54. for(j=; j<=n; j++)
  55. scanf("%d", &a[i][j]);
  56.  
  57. printf("%d\n", DFS(n, k, , ));
  58. }
  59.  
  60. return ;
  61. }

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

 
 

FatMouse and Cheese

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7774    Accepted Submission(s): 3221

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 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.

 
Input
There 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. 

 
Output
For 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
 
Source

(记忆化搜索) FatMouse and Cheese(hdu 1078)的更多相关文章

  1. FatMouse and Cheese HDU - 1078 dp

    #include<cstdio> #include<iostream> #include<cstring> using namespace std; int n,k ...

  2. hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)

    pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/ ...

  3. HDU - 1078 FatMouse and Cheese (记忆化搜索)

    FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...

  4. 随手练——HDU 1078 FatMouse and Cheese(记忆化搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意: 一张n*n的格子表格,每个格子里有个数,每次能够水平或竖直走k个格子,允许上下左右走,每次走的格子 ...

  5. hdu 1078 FatMouse and Cheese(简单记忆化搜索)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意:给出n*n的格子,每个各自里面有些食物,问一只老鼠每次走最多k步所能吃到的最多的食物 一道 ...

  6. HDU 1078 FatMouse and Cheese 记忆化搜索DP

    直接爆搜肯定超时,除非你加了某种凡人不能想出来的剪枝...555 因为老鼠的路径上的点满足是递增的,所以满足一定的拓补关系,可以利用动态规划求解 但是复杂的拓补关系无法简单的用循环实现,所以直接采取记 ...

  7. !HDU 1078 FatMouse and Cheese-dp-(记忆化搜索)

    题意:有一个n*n的格子.每一个格子里有不同数量的食物,老鼠从(0,0)開始走.每次下一步仅仅能走到比当前格子食物多的格子.有水平和垂直四个方向,每一步最多走k格,求老鼠能吃到的最多的食物. 分析: ...

  8. hdu1078 FatMouse and Cheese(记忆化搜索)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1078" target="_blank">http://acm. ...

  9. 记忆化搜索,FatMouse and Cheese

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1107 http://acm.hdu.edu.cn/showpro ...

  10. hdu1078 FatMouse and Cheese(记忆化搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1078 题目大意: 题目中的k表示横向或者竖直最多可曾经进的距离,不可以拐弯.老鼠的出发点是(1,1) ...

随机推荐

  1. Angular5学习札记

    1.使用cnpm安装jQuery和bootstrap后,页面没有加载的问题 -使用cnpm安装的路径和使用npm安装路径不一样,解决如下: 把css路径改成"../node_modules/ ...

  2. (转)JavaScript的压缩

    JavaScript的压缩 (转自)http://blog.csdn.net/ybygjy/article/details/6995435 简述 如果非常着急,这块可以跳过直接从约束条件开始也行. J ...

  3. Numpy copy & deep copy

    1. '='的赋值方式会带有关联性 >>> import numpy as np >>> a = np.arange(4) >>> b = a & ...

  4. Ant.OutputIsUnreadableCode

    Ant在Mac OS X终端中的输出乱码的问题 1. 问题: 在用Ant脚本进行构建Android App时,在编译失败时,Ant 输出有乱码. 2. 环境: Mac OS X, 简体中文版.在Ter ...

  5. 简单使用limma做差异分析

    简单使用limma做差异分析 Posted: 五月 12, 2017  Under: Transcriptomics  By Kai  no Comments 首先需要说明的是,limma是一个非常全 ...

  6. BZOJ1079或洛谷2476 [SCOI2008]着色方案

    一道记忆化搜索 BZOJ原题链接 洛谷原题链接 发现对于能涂木块数量一样的颜色在本质上是一样的,所以可以直接压在一个状态,而这题的数据很小,直接暴力开\(6\)维. 定义\(f[a][b][c][d] ...

  7. 20172325 2018-2019-2 《Java程序设计》第五周学习总结

    20172325 2018-2019-2 <Java程序设计>第五周学习总结 教材学习内容总结 本次学习第九章内容,主要学习查找和排序. 查找 查找的定义:是一个过程,即在某个项目组中寻找 ...

  8. C++变量存储类别和内存四区

    变量存储类别 变量声明/定义的一般形式: 存储类别 数据类型 变量名 存储类别指的是数据在内存中存储的方法.存储方法分为静态存储和动态存储两大类.标准C语言为变量.常量和函数定义了4种存储类型:ext ...

  9. Linux 终端设备

    <Linux终端设备详解> https://www.cnblogs.com/shineshqw/articles/2423989.html

  10. insert执行错误,怎么样获取具体的错误原因

    1.开启debug 2.去runtime里面去找最后执行的SQL