Uva1025 A Spy in the Metro
#include <iostream>
#include <cstring>
#include <cstdio> using namespace std; int t[];
int dp[][]; //dp[i][j]记录在第i个车站需要等待时间
int l[][], r[][]; //l[i][j]第i个车站在j时刻是否有从左边行驶的车辆 r[i][j]右方向同l[i][j]
int num = ;
int min(int a,int b){
if(a<b) return a;
return b;
}
int main()
{
int n,T,m,cur;
while (scanf("%d",&n)!=EOF )
{
memset(l, , sizeof(l));
memset(r, , sizeof(r));
memset(dp, 0x3f, sizeof(dp));
cin>>T;
for(int i=;i<n;i++) cin>>t[i];
cin>>m;
for(int i=;i<=m;i++)
{
cin>>cur;
for(int j=;j<=n;j++)
{
l[j][cur] = , cur += t[j];
}
}
cin>>m;
for(int i=;i<=m;i++)
{
cin>>cur;
for(int j=n;j>;j--)
{
r[j][cur] = , cur += t[j - ];
}
}
dp[n][T]=;
for(int j=T-;j>=;j--)
for(int i=;i<=n;i++)
{
dp[i][j]=dp[i][j+]+;
if(l[i][j]) dp[i][j] = min(dp[i][j],dp[i+][j+t[i]]);
if(r[i][j]) dp[i][j] = min(dp[i][j],dp[i-][j+t[i-]]);
}
cout<< "Case Number "<<++num<<": ";
if(dp[][]>T)
cout<<"impossible"<<endl;
else
cout<<dp[][]<<endl;
}
return ;
}
Uva1025 A Spy in the Metro的更多相关文章
- UVA1025 A Spy in the Metro —— DP
题目链接: https://vjudge.net/problem/UVA-1025 题解: 详情请看紫书P267. 与其说是DP题,我觉得更像是模拟题,特别是用记忆化搜索写. 递推: #include ...
- 【动态规划】[UVA1025]A Spy in the Metro 城市里的间谍
参考:https://blog.csdn.net/NOIAu/article/details/71517440 https://blog.csdn.net/c20180630/article/deta ...
- 题解:UVa1025 A Spy in the Metro
原题链接 pdf 题目大意 给出一张无向图图,求该图的最小瓶颈生成树. 无向图的瓶颈生成树:无向图\(G\)的一颗瓶颈生成树是这样的一颗生成树:它最大的边权值在\(G\)的所有生成树中是最小的.瓶颈生 ...
- 【Uva1025 A Spy in the Metro】动态规划
题目描述 某城市地铁是线性的,有n(2≤n≤50)个车站,从左到右编号1~n.有M1辆列车从第1站开始往右开,还有M2辆列车从第n站开始往左开.列车在相邻站台间所需的运行时间是固定的,因为所有列车的运 ...
- UVA - 1025 A Spy in the Metro[DP DAG]
UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especia ...
- 洛谷2583 地铁间谍 (UVa1025A Spy in the Metro)
洛谷2583 地铁间谍(UVa1025A Spy in the Metro) 本题地址:http://www.luogu.org/problem/show?pid=2583 题目描述 特工玛利亚被送到 ...
- UVA1025-A Spy in the Metro(动态规划)
Problem UVA1025-A Spy in the Metro Accept: 713 Submit: 6160Time Limit: 3000 mSec Problem Descriptio ...
- uva 1025 A Spy in the Metro 解题报告
A Spy in the Metro Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug Secr ...
- uva 1025 A Spy int the Metro
https://vjudge.net/problem/UVA-1025 看见spy忍俊不禁的想起省赛时不知道spy啥意思 ( >_< f[i][j]表示i时刻处于j站所需的最少等待时间,有 ...
随机推荐
- 【C/C++学院】0723-32位与64位/调戏窗体程序/数据分离算法/内存检索/二分查找法/myVC
[送给在路上的程序猿] 对于一个开发人员而言,能够胜任系统中随意一个模块的开发是其核心价值的体现. 对于一个架构师而言,掌握各种语言的优势并能够运用到系统中,由此简化系统的开发,是其架构生涯的第一步. ...
- 转: 私人珍藏的Chrome插件,吐血推荐
转:来自 http://stormzhang.com/devtools/2016/01/15/google-chrome-extension/
- [Javascript] Deep merge in Javascript with Ramda.js mergeDeepWith
Javascript's Object.assign is shadow merge, loadsh's _.merge is deep merge, but has probem for array ...
- iOS 调用第三方地图进行导航
//支持的地图 { _model = model; //支持的地图 NSMutableArray *maps = [NSMutableArray array]; //苹果原生地图-苹果原生地图方法和其 ...
- axios 取消请求
解决思路 在发送第二次请求的时候如果第一次请求还未返回,则取消第一次请求,以保证后发送的请求返回的数据不会被先发送的请求覆盖. axios官方文档取消请求说明 方法一: const CancelTok ...
- Python人体肤色检测
代码地址如下:http://www.demodashi.com/demo/12967.html Python人体肤色检测 概述 本文中的人体肤色检测功能采用 OpenCV 库实现, OpenCV是一个 ...
- mysql无法启动ERROR! MySQL is running but PID file could not be found ?
转载于:http://blog.csdn.net/wuzhilon88/article/details/17616635 第一种方法:可能是硬盘满了,清理下垃圾文件. 第二种: 查看下数据库运行状态 ...
- Jenkins插件开发资料
原文地址:http://www.ciandcd.com/?p=181 Jenkins plugin 开发: Document http://hudson-ci.org/docs/index.html ...
- RabbitMQ消息队基本概念
RabbitMQ简介 AMQP,即Advanced Message Queuing Protocol,高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设计.消息中间件主要用于组件之间的 ...
- Vivado 与 Modelsim 联合仿真
1 编译库 用命令行 用vivado工具 vivado 有很多 IP核的接口 已经与 ISE的核 不太一样了,比如fir ,接口就是这样的: fir_lp fir_lp_ip( .aclk ( ...