题目链接: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. knockoutjs -- all built-in buildings

    所有可用的binding值 文字和显示:visible, text, html, css, style, attr 流程控制:foreach, if, ifnot, with form字段:click ...

  2. Hadoop + HBase (自带zookeeper 也可单独加) 集群部署

    Hadoop+HBase搭建云存储总结 PDF http://www.linuxidc.com/Linux/2013-05/83844.htm HBase 结点之间时间不一致造成regionserve ...

  3. Redis配置和常用命令

    redis.conf配置文件: 引用 #是否作为守护进程运行 daemonize yes #配置pid的存放路径及文件名,默认为当前路径下 pidfile redis.pid #Redis默认监听端口 ...

  4. AutoFac文档14(转载)

    目录 开始 Registering components 控制范围和生命周期 用模块结构化Autofac xml配置 与.net集成 深入理解Autofac 指导 关于 词汇表 激活事件 在compo ...

  5. Memory leak patterns in JavaScript

    Handling circular references in JavaScript applications Plugging memory leaks in JavaScript is easy ...

  6. (oneway void) release中oneway的意思

    oneway is used with the distributed objects API, which allows use of objective-c objects between dif ...

  7. MySql导入导出数据库(含远程导入导出)

    一.导入导出本地数据库    导出: 1.先运行cmd,cd 到mysql安装目录中的bin文件夹 2.mysqldump -u root -p 数据库名 > 导出文件名.sql 其他情况下: ...

  8. makefile之wildcard函数

    $(wildcard PATTERN) 函数功能: 获取匹配 PATTERN 的所有对象 返回值: 使用空格分割的匹配对象列表 1. 示例1

  9. 整合hibernate的lucene大数据模糊查询

      大数据模糊查询lucene 对工作单使用 like模糊查询时,实际上 数据库内部索引无法使用 ,需要逐条比较查询内容,效率比较低在数据量很多情况下, 提供模糊查询性能,我们可以使用lucene全文 ...

  10. django 判断用户是否登陆

    基于类的视图登陆