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

题意:给出n, k,然后给出n*n的地图,(下标0~n-1),有一只老鼠从(0,0)处出发,只能走直线,并且目标点的数值比当前点要大。每次最长可以走k步,问最长的一条链的数值和。

用一个二维数组dp(i,j)表示某一格出发的时候最长链的数值和,然后dfs。

 #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; const int maxn = ;
const int dx[] = {, , , -};
const int dy[] = {, -, , };
int n, k;
int G[maxn][maxn];
int dp[maxn][maxn]; bool ok(int x, int y) {
return x >= && y >= && x < n && y < n;
} int dfs(int x, int y) {
if(dp[x][y]) return dp[x][y];
int cur = ;
for(int i = ; i < ; i++) {
for(int j = ; j <= k; j++) {
int xx = x + dx[i] * j;
int yy = y + dy[i] * j;
if(ok(xx, yy) && G[xx][yy] > G[x][y]) {
cur = max(cur, dfs(xx, yy));
}
}
}
return dp[x][y] = cur + G[x][y];
} inline bool scan_d(int &num) {
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<''||in>'')) in=getchar();
if(in=='-'){ IsN=true;num=;}
else num=in-'';
while(in=getchar(),in>=''&&in<=''){
num*=,num+=in-'';
}
if(IsN) num=-num;
return true;
} int main() {
// freopen("in", "r", stdin);
while(~scanf("%d%d", &n, &k) && n + k != -) {
memset(dp, , sizeof(dp));
for(int i = ; i < n; i++) {
for(int j = ; j < n; j++) {
scan_d(G[i][j]);
}
}
printf("%d\n", dfs(, ));
}
return ;
}

[HDOJ1078]FatMouse and Cheese(记忆化搜索)的更多相关文章

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

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

  2. P - FatMouse and Cheese 记忆化搜索

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

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

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

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

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

  5. hdu1078 FatMouse and Cheese —— 记忆化搜索

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 代码1: #include<stdio.h>//hdu 1078 记忆化搜索 #in ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 老鼠初始时在n*n的矩阵的(0 , 0)位置,每次可以向垂直或水平的一个方向移动1到k格,每次移 ...

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

    详见代码 #include <iostream> #include <cstdio> #include <cstdlib> #include <memory. ...

  8. HDU ACM 1078 FatMouse and Cheese 记忆化+DFS

    题意:FatMouse在一个N*N方格上找吃的,每一个点(x,y)有一些吃的,FatMouse从(0,0)的出发去找吃的.每次最多走k步,他走过的位置能够吃掉吃的.保证吃的数量在0-100.规定他仅仅 ...

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

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

随机推荐

  1. 【ContestHunter】【弱省胡策】【Round2】

    官方题解:http://wyfcyx.is-programmer.com/posts/95490.html A 目前只会30分的暴力……DP好像很神的样子0.0(听说可以多次随机强行算? //Roun ...

  2. 最全的CMD命令

    CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本.文件系统版本) . appwiz.cpl:程序和功能 . calc:启动计算器 . certmgr.ms ...

  3. safeseh+dep保护绕过

    [文章作者]       :h_one [漏洞程序名称]:mplayer.exe [漏洞类型]       :缓冲区溢出 [保护方式]       :safeseh+dep [操作平台]       ...

  4. Altium Designer 使用小结

    今天刚把做好的PCB文件交给工厂去制板,阶段工作告一段落,来一个小总结. 前一段时间复习完C语言之后,在中国知网上搜索用单片机实现的小制作,找比较有意思,又不需要太多外专业知识的东西,然后就相中了超声 ...

  5. Yahoo, Steve blog

    Performance Research Domain Sharding revisited A Software Developer's Guide to HTTP How the Browser ...

  6. TKStudio 4.6IDE Warning: L6310W: Unable to find ARM libraries.

    我也遇到了同样的问题.搞了很久,按下面的操解决了 内容转至:http://bbs.zlgmcu.com/dv_rss.asp?s=xh&boardid=43&id=23032& ...

  7. SELINUX设为Disable 影响java SSH工具包Jsch 0.1.49.jar的一个案例

    最近项目中遇到一个典型事件,当RHEL 的SELINUX设为DISABLE时 使用JAVA的Jsch 库调用SSH命令时将随机返回空字符串,我使用的版本是0.1.49,最新版本0.1.51未测试. 关 ...

  8. DevSecOps简介(二)

    越来越多的组织机构开始采取 DevOps 实践,作为呼应,本文将概括强调很多人认为这一实践缺失的部分:安全.随着 NV (网络虚拟化) 和 NFV (网络功能虚拟化)的使用率逐步攀升,在开发和部署流程 ...

  9. 高质量图形库:pixellib

    点这里 pixellib 是高质量 2D 图形库: 高质量抗锯齿,矢量图形绘制 多种图像格式: RGB, BGR, ARGB, ABGR, RGBA, BGRA 8 / 15 / 16 / 24 / ...

  10. ResourceBundle使用

    一.认识国际化资源文件   这个类提供软件国际化的捷径.通过此类,可以使您所编写的程序可以:          轻松地本地化或翻译成不同的语言          一次处理多个语言环境          ...