题意:

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的更多相关文章

  1. 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 ...

  2. 洛谷2583 地铁间谍 (UVa1025A Spy in the Metro)

    洛谷2583 地铁间谍(UVa1025A Spy in the Metro) 本题地址:http://www.luogu.org/problem/show?pid=2583 题目描述 特工玛利亚被送到 ...

  3. UVA1025-A Spy in the Metro(动态规划)

    Problem UVA1025-A Spy in the Metro Accept: 713  Submit: 6160Time Limit: 3000 mSec Problem Descriptio ...

  4. uva 1025 A Spy in the Metro 解题报告

    A Spy in the Metro Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug Secr ...

  5. 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 ...

  6. UVA 1025 -- A Spy in the Metro (DP)

     UVA 1025 -- A Spy in the Metro  题意:  一个间谍要从第一个车站到第n个车站去会见另一个,在是期间有n个车站,有来回的车站,让你在时间T内时到达n,并且等车时间最短, ...

  7. UVa 1025 A Spy in the Metro(动态规划)

    传送门 Description Secret agent Maria was sent to Algorithms City to carry out an especially dangerous ...

  8. 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 ...

  9. 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 ...

  10. uva 1025 A Spy int the Metro

    https://vjudge.net/problem/UVA-1025 看见spy忍俊不禁的想起省赛时不知道spy啥意思 ( >_< f[i][j]表示i时刻处于j站所需的最少等待时间,有 ...

随机推荐

  1. CKeditor 配置使用

    CKeditor 配置使用 一.使用方法:1.在页面<head>中引入ckeditor核心文件ckeditor.js<script type="text/javascrip ...

  2. 【零基础学习iOS开发】【02-C语言】05-进制

    上一讲简单介绍了常量和变量,这讲补充一点计算机的基础知识---进制. 我们先来看看平时是如何表示一个整数的,最常见的肯定是用阿拉伯数字表示,比如“十二”,我们可以用12来表示,其实这种表示方式是基于一 ...

  3. Qt网络通信骨架解析,QtClient QtServer QtSerialPort

    http://blog.csdn.net/Dr_Abel/article/details/52469134#t18

  4. java:对象的转型

    面向对象编程有三个特征,即封装.继承和多态,学习多态必须了解向上转型和向下转型. 一.向上转型:将子类对象赋值给父类的引用 动物 a=new 狗()://这就为向上转型 向上转型都会成功,是安全的. ...

  5. JavaScript DOM编程基础精华01(DOM入门,DOM模型和获取页面元素,事件,window对象的方法)

    DOM入门 DOM就是Html页面的模型,将每个标签都做为一个对象,JavaScript通过调用DOM中的属性.方法就可以对网页中的文本框.层等元素进行编程控制.比如通过操作文本框的DOM对象,就可以 ...

  6. PowerDesigner的样式设置

    原文:PowerDesigner的样式设置 PD提供了强大的配置功能,可以对生成的数据库对象命名.数据模型的展现进行设置.这里首先讲下样式的设置. 颜色和字体设置 1.单独设置某个对象的颜色和字体 1 ...

  7. 模拟在table中移动鼠标,高亮显示鼠标所在行

    在项目中有这样一个需求,在table中移动鼠标时,鼠标所在行高亮显示,其他行正常显示,为此做了一个模拟. 具体代码如下: <!DOCTYPE html> <html xmlns=&q ...

  8. POJ 3468 A Simple Problem with Integers(树状数组)

    题目链接:http://poj.org/problem?id=3468 题意:给出一个数列,两种操作:(1)将区间[L,R]的数字统一加上某个值:(2)查询区间[L,R]的数字之和. 思路:数列A,那 ...

  9. 使用 Oracle GoldenGate 在 Microsoft SQL Server 和 Oracle Database 之间复制事务

    使用 Oracle GoldenGate 在 Microsoft SQL Server 和 Oracle Database 之间复制事务 作者:Nikolay Manchev 分步构建一个跨这些平台的 ...

  10. git跨平台换行符不兼容

    https://help.github.com/articles/dealing-with-line-endings/#platform-all