uva 1025 A Spy int the Metro
https://vjudge.net/problem/UVA-1025
看见spy忍俊不禁的想起省赛时不知道spy啥意思 ( >_<
f[i][j]表示i时刻处于j站所需的最少等待时间,有三种可能,一是i-1时刻就在这里然后等待了1时刻 f[i][j]=f[i-1][j]+1 ; 二是正好由由左边相邻的一个车站开过来(如果可以的话) f[i][j]=f[i-t[j-1]][j-1]; 三是正好由右边的车站开过来(if can) f[i][j]=f[i-t[j]][j+1]; 取三者的最小值就好,最后如果f[T][N]>=inf表示impossible.
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
int t[],tl[],tr[];
int f[][];
bool can[][][];
int main()
{
int N,T,M1,M2,i,j,k=;
while(cin>>N&&N){
cin>>T;
for(i=;i<N;++i) scanf("%d",t+i);
memset(f,inf,sizeof(f));
memset(can,,sizeof(can));
cin>>M1;
for(i=;i<=M1;++i)
{
int s;
scanf("%d",tl+i);
for(j=,s=tl[i];j<=N&&s<=T;s+=t[j++])
{
can[s][j][]=;
}
}
cin>>M2;
for(i=;i<=M2;++i)
{
int s;
scanf("%d",tr+i);
for(j=N,s=tr[i];j>=&&s<=T;s+=t[j-],j--)
can[s][j][]=;
}
f[][]=;
for(i=;i<=T;++i)
{
for(j=;j<=N;++j)
{
f[i][j]=f[i-][j]+;
if(j>&&i-t[j-]>=&&can[i-t[j-]][j-][])
f[i][j]=min(f[i][j],f[i-t[j-]][j-]);
if(j<N&&i-t[j]>=&&can[i-t[j]][j+][])
f[i][j]=min(f[i][j],f[i-t[j]][j+]);
}
}
printf("Case Number %d: ",++k);
if(f[T][N]>=inf) puts("impossible");
else cout<<f[T][N]<<endl;
}
return ;
}
/*
4
55
5 10 15
4
0 5 10 20
4
0 5 10 15 ans=5
*/
uva 1025 A Spy int 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 ...
- 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 解题报告
A Spy in the Metro Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug Secr ...
- UVa 1025 A Spy in the Metro(动态规划)
传送门 Description Secret agent Maria was sent to Algorithms City to carry out an especially dangerous ...
- 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 in the Metro
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35913 预处理出每个时间.每个车站是否有火车 为了方便判断是否可行,倒推处理 ...
- DAG的动态规划 (UVA 1025 A Spy in the Metro)
第一遍,刘汝佳提示+题解:回头再看!!! POINT: dp[time][sta]; 在time时刻在车站sta还需要最少等待多长时间: 终点的状态很确定必然是的 dp[T][N] = 0 ---即在 ...
- World Finals 2003 UVA - 1025 A Spy in the Metro(动态规划)
分析:时间是一个天然的序,这个题目中应该决策的只有时间和车站,使用dp[i][j]表示到达i时间,j车站在地上已经等待的最小时间,决策方式有三种,第一种:等待一秒钟转移到dp[i+1][j]的状态,代 ...
- UVa 1025 A Spy in the Metro (DP动态规划)
题意:一个间谍要从第一个车站到第n个车站去会见另一个,在是期间有n个车站,有来回的车站,让你在时间T内时到达n,并且等车时间最短, 也就是尽量多坐车,最后输出最少等待时间. 析:这个挺复杂,首先时间是 ...
随机推荐
- Python利用subprocess起进程
from multiprocessing import Process, Pool import time import subprocess def task(msg): print 'hello, ...
- 【生产问题】-dbcc checkdb报错-数据页故障
更多操作参考:https://www.cnblogs.com/gered/p/9435282.html [生产问题]-dbcc checkdb报错-数据页故障 数据页故障,索引页故障 use db_t ...
- C#编写图书列表winform
Book.cs文件 using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...
- 函数编程——匿名函数与lambda(一)
python允许用lambda关键字创造匿名函数. 匿名函数是因为不需要以标准的方式来声明,比如说,使用def语句. 但是,作为函数,它们也能有参数. 一个完整的lambda“语句”代表了一个表达式, ...
- XSS - 禁止浏览器读取Cookie - HttpOnly
1.什么是HttpOnly? 如果您在cookie中设置了HttpOnly属性,那么通过js脚本将无法读取到cookie信息,这样能有效的防止XSS攻击,具体一点的介绍请google进行搜索. C ...
- XSS Attacks - Exploiting XSS Filter
XSS Attacks - Exploiting XSS Filter mramydnei · 2015/12/21 10:11 from:http://l0.cm/xxn/ 0x00 前言 这又是一 ...
- 动手动脑:String.equals()的使用方法
public class StringEquals { /** * @param args the command line arguments */ public static void main( ...
- 【Tech】单点登录系统CAS客户端demo
服务器端配置请参考: http://www.cnblogs.com/sunshineatnoon/p/4064632.html 工具:myeclipse或者javaee-eclipse 1.启动jav ...
- 【Head First Servlets and JSP】迷你MVC:JarDownload的完整实现
1.首先,写一个download.html放至D:\apache-tomcat-7.0.77\webapps\JarDownload-v1. <!DOCTYPE HTML> <htm ...
- 【FAQ系列】Relay log 导致复制启动失败
今天在使用冷备份文件重做从库时遇到一个报错,值得研究一下. 版本:MySQL5.6.27 一.报错现象 dba:(none)> start slave; ERROR (HY000): Slave ...