题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21261

思路:此题需要记忆化搜索,dp[x][y][t]表示当前状态下是否是否有可能点(x,y)上有贼,0表示不可能,1表示可能,然后及时记忆化搜索。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define MAXN 111
typedef pair<int,int>PP; int n,m,Time,cnt;
int dp[MAXN][MAXN][MAXN];
int dir[][]={{,-},{-,},{,},{,},{,}};
vector<vector<PP> >ans; bool Judge(int x,int y)
{
if(x>=&&x<=m&&y>=&&y<=n)return true;
return false;
} bool dfs(int x,int y,int t)
{
if(dp[x][y][t]!=-)return dp[x][y][t];
if(t>=Time){
cnt++;
ans[t].push_back(make_pair(x,y));
return dp[x][y][t]=;
}
dp[x][y][t]=;
for(int i=;i<;i++){
int xx=x+dir[i][],yy=y+dir[i][];
if(!Judge(xx,yy))continue;
if(dfs(xx,yy,t+)){
dp[x][y][t]=;
}
}
if(dp[x][y][t]==){
ans[t].push_back(make_pair(x,y));
}
return dp[x][y][t];
} int main()
{
int T,t,a,b,c,d,Cas=,flag;
while(~scanf("%d%d%d",&n,&m,&Time)){
if(n==&&m==&&Time==)break;
scanf("%d",&T);
memset(dp,-,sizeof(dp));
while(T--){
scanf("%d%d%d%d%d",&t,&a,&b,&c,&d);
for(int i=b;i<=d;i++)
for(int j=a;j<=c;j++)
dp[i][j][t]=;
}
ans.clear();
ans.resize(MAXN);
cnt=flag=;
for(int i=;i<=m;i++){
for(int j=;j<=n;j++){
if(dp[i][j][]==-)dfs(i,j,);
}
}
printf("Robbery #%d:\n",Cas++);
if(cnt==){
puts("The robber has escaped.");
}else {
for(int i=;i<=Time;i++){
if((int)ans[i].size()==){
flag=;
printf("Time step %d: The robber has been at %d,%d.\n",i,ans[i][].second,ans[i][].first);
}
}
if(!flag)puts("Nothing known.");
}
puts("");
}
return ;
}

uva 707(记忆化搜索)的更多相关文章

  1. UVa 10118 记忆化搜索 Free Candies

    假设在当前状态我们第i堆糖果分别取了cnt[i]个,那么篮子里以及口袋里糖果的个数都是可以确定下来的. 所以就可以使用记忆化搜索. #include <cstdio> #include & ...

  2. UVa 10400 记忆化搜索

    #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...

  3. Substring Uva 11468_记忆化搜索 + AC自动机

    Code: #include<cstdio> #include<cstring> #include<queue> using namespace std; cons ...

  4. uva 10581 - Partitioning for fun and profit(记忆化搜索+数论)

    题目链接:uva 10581 - Partitioning for fun and profit 题目大意:给定m,n,k,将m分解成n份,然后依照每份的个数排定字典序,而且划分时要求ai−1≤ai, ...

  5. UVA - 10118Free Candies(记忆化搜索)

    题目:UVA - 10118Free Candies(记忆化搜索) 题目大意:给你四堆糖果,每一个糖果都有颜色.每次你都仅仅能拿随意一堆最上面的糖果,放到自己的篮子里.假设有两个糖果颜色同样的话,就行 ...

  6. UVA - 10917 - Walk Through the Forest(最短路+记忆化搜索)

    Problem    UVA - 10917 - Walk Through the Forest Time Limit: 3000 mSec Problem Description Jimmy exp ...

  7. UVa 10285 Longest Run on a Snowboard - 记忆化搜索

    记忆化搜索,完事... Code /** * UVa * Problem#10285 * Accepted * Time:0ms */ #include<iostream> #includ ...

  8. 状压DP+记忆化搜索 UVA 1252 Twenty Questions

    题目传送门 /* 题意:给出一系列的01字符串,问最少要问几个问题(列)能把它们区分出来 状态DP+记忆化搜索:dp[s1][s2]表示问题集合为s1.答案对错集合为s2时,还要问几次才能区分出来 若 ...

  9. 【UVA 437】The Tower of Babylon(记忆化搜索写法)

    [题目链接]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

随机推荐

  1. 41、java与mysql乱码的问题

    解决方法一:(最重要的一种方法)你看下my.ini,有无 [MySQL] default-character-set=utf8 [client] default-character-set=utf8 ...

  2. Direct X和OpenGL是什么及有何区别

    摘自:http://mtoou.info/directx-opengl-shenme/ 提起图形和显卡,尤其是玩电脑游戏的时候(通常是安装时)很多人是不是立刻就想起了一个名词叫做Direct X,通常 ...

  3. 微信小程序之底部弹框预约插件

    代码地址如下:http://www.demodashi.com/demo/13982.html 一.前期准备工作: 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.c ...

  4. TextWatcher

    对于一些需求,如非法字符限制(例如不允许输入#号,如果输入了#给出错误提示),做成动态判断更方便一些,而且容易扩展: 在Android里使用TextWatcher接口可以很方便的对EditText进行 ...

  5. Win10 环境安装tesseract-ocr 4.00并配置环境变量

    Tesseract-OCR的Training简明教程 https://blog.csdn.net/blueheart20/article/details/53207176 一.安装: 选择对应版本,h ...

  6. c++,当const char*为0时,不能将其直接赋给string

    下面程序会崩溃: const char* t_objName = (obj!=NULL)?obj->getName(): 0; string objName=t_objName; cout< ...

  7. php从memcache读取数据再批量写入mysql的方法

    这篇文章主要介绍了php从memcache读取数据再批量写入mysql的方法,可利用memcache缓解服务器读写压力,并实现数据库数据的写入操作,非常具有实用价值,需要的朋友可以参考下. 用 Mem ...

  8. maple minimax函数

    numapprox[minimax] - minimax rational approximation Calling Sequence   minimax(f, x=a..b, [m, n], w, ...

  9. iOS应用程序状态切换相关

    一.iOS应用程序状态机一共有五种状态: 1. Not running:应用还没有启动,或者应用正在运行但是途中被系统停止. 2. Inactive:当前应用正在前台运行,但是并不接收事件(当前或许正 ...

  10. Hystrix的原理与使用

    转载自:https://segmentfault.com/a/1190000005988895              http://blog.csdn.net/xiaoyu411502/artic ...