A Spy in the Metro
题意:
n个车站,已知到达相邻车站的时间,有m1辆车从1站出发已知发车时间,有m2辆车从n站出发已知发车时间,求从1到达n所需等车的总时间最小。
分析:
有三种情况,在原地等,乘左到右的车,乘右到左的车dp[i][j]=min(dp[i][j+1]+1,dp[i-1][j+t[i-1]],dp[i+1][t[i]]);
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int dp[][],ld[][],rd[][];
int n,T,m,t[];
void solve(){
memset(dp,0x3f,sizeof(dp));
dp[n][T]=;
for(int j=T-;j>=;--j)
for(int i=;i<=n;++i)
{
dp[i][j]=dp[i][j+]+;
if(ld[i][j])dp[i][j]=min(dp[i][j],dp[i-][j+t[i-]]);
if(rd[i][j])dp[i][j]=min(dp[i][j],dp[i+][j+t[i]]);
}
if(dp[][]>T)printf("impossible\n");
else printf("%d\n",dp[][]);
}
int main()
{
int ca=;
while(~scanf("%d",&n)){
if(n==)break;
scanf("%d",&T);
for(int i=;i<n;++i)
scanf("%d",&t[i]);
int tmp;
memset(ld,,sizeof(ld));
memset(rd,,sizeof(rd));
scanf("%d",&m);
while(m--){
scanf("%d",&tmp);
for(int i=;i<=n;++i)
{
rd[i][tmp]=;
tmp+=t[i];
}
}
scanf("%d",&m);
while(m--){
scanf("%d",&tmp);
for(int i=n;i>;--i)
{
ld[i][tmp]=;
tmp+=t[i-];
}
}
printf("Case Number %d: ",++ca);
solve();
}
return ;
}
A Spy in the Metro的更多相关文章
- 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 A Spy in the Metro(洛谷 P2583 地铁间谍)
A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especially dangero ...
- UVA 1025 -- A Spy in the Metro (DP)
UVA 1025 -- A Spy in the Metro 题意: 一个间谍要从第一个车站到第n个车站去会见另一个,在是期间有n个车站,有来回的车站,让你在时间T内时到达n,并且等车时间最短, ...
- UVa 1025 A Spy in the Metro(动态规划)
传送门 Description Secret agent Maria was sent to Algorithms City to carry out an especially dangerous ...
- UVA1025---A Spy in the Metro(DP)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35913 Secret agent Maria was sent to Alg ...
- UVA 1025 A Spy in the Metro 【DAG上DP/逆推/三维标记数组+二维状态数组】
Secret agent Maria was sent to Algorithms City to carry out an especially dangerous mission. After s ...
- uva 1025 A Spy int the Metro
https://vjudge.net/problem/UVA-1025 看见spy忍俊不禁的想起省赛时不知道spy啥意思 ( >_< f[i][j]表示i时刻处于j站所需的最少等待时间,有 ...
随机推荐
- POJ 2240 Arbitrage(floyd)
http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...
- Apache 下SVN项目管理使用说明
Apache 下SVN项目管理使用说明 (1)Apaceh和SVN先要装好. (2)在apache的目录下找到httpd.conf文件,在最后一行增加如下配置 Include conf/svn.pro ...
- iOS 开发-- Runtime 1小时入门教程
1小时让你知道什么是Objective-C Runtime,并对它有一定的基本了解,可以在开发过程中运用自如. 三.Objective-C Runtime到底是什么东西? 简而言之,Objective ...
- Java学习笔记之:Java封装
一.引言 在面向对象程式设计方法中,封装(英语:Encapsulation)是指,一种将抽象性函式接口的实作细节部份包装.隐藏起来的方法. 封装可以被认为是一个保护屏障,防止该类的代码和数据被外部类定 ...
- 用 React 编写SVG图表
1.代码 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="U ...
- Android:布局单位换算
一.px 像素,是屏幕上显示数据的最基本的点. 二.dpi dpi(Dots Per Inch):每英寸点数,也可称为像素密度,即屏幕对角线像素值÷英寸值 比如480x800分辨率4.0英寸的手机计算 ...
- VC6.0下string不能用pusk_back,可用+=代替
2013-09-11 21:14:32 在VS下运行正确的代码,拿到VC6.0下,编译出错,提示: error C2039: 'push_back' : is not a member of 'bas ...
- 字符设备 register_chrdev_region()、alloc_chrdev_region() 和 register_chrdev()
1. 字符设备结构体 内核中所有已分配的字符设备编号都记录在一个名为 chrdevs 散列表里.该散列表中的每一个元素是一个 char_device_struct 结构,它的定义如下: static ...
- cololection
package cn.bjsxt.col; /** * 简化迭代器原理 * hasNext * next * @author Administrator * */ public class MyArr ...
- NFC(1)NFC简介,3种模式
简介 NFC(Near Field Communication,近场通信),是一种数据传输技术.但与Wi-Fi.蓝牙.红外线等数据传输技术的一个主要差异就 是有效距离一般不能超过4厘米. NFC支持如 ...