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,并且等车时间最短, 也就是尽量多坐车,最后输出最少等待时间. 析:这个挺复杂,首先时间是 ...
随机推荐
- 剑指offer 面试66题
面试66题: 题目:构建乘积数组 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]* ...
- selenium之坑:点击后页面刷新重新获取刷新前的页面(StaleElementReferenceException:Message:Element not found in the cache...)
循环点击一列链接,但只能点到第一个,第二个失败,这是为什么,因为第二个已经是新页面,当然找不到之前页面的元素,虽然元素没变,甚至是后退回来,页面都没有变,为什么是新页面,页面长的一样不代表是同一张页面 ...
- Android:日常学习笔记(8)———探究UI开发(5)
Android:日常学习笔记(8)———探究UI开发(5) ListView控件的使用 ListView概述 A view that shows items in a vertically scrol ...
- jQuery:自学笔记(4)——事件与事件对象
jQuery:自学笔记(4)——事件与事件对象 jQuery中的事件 什么是事件 所谓事件,就是被对象识别的操作,即操作对象队环境变化的感知和反应,例如单击按钮或者敲击键盘上的按键. 所谓事件流,是指 ...
- android studio的安装和卸载
安装: (待补充) 卸载: (如何彻底卸载才能达到第二次安装不受第一次安装失败的影响呢?) 1.找到安装目录,运行卸载文件.(不用清注册表,这是和卸载mysql的不同,只要把相关的文件夹,文件清楚即可 ...
- Loadrunder之脚本篇——参数化在场景中的运用
Action() { lr_eval_string("{NewParam}"); lr_eval_string("{NewParam}"); return 0; ...
- 【LeetCode】【动态规划】Edit Distance
描述 Given two words word1 and word2, find the minimum number of operations required to convert word1 ...
- nginx安装使用
1.前言 当我们希望分享自己的文件时,有多种方式,局域网可以采用共享,rtx传输,qq传输,发送到邮箱,直接u盘拷贝等等.但最简单的就是开启本地服务器,其他电脑通过网页的方式直接下载,这里介绍使用ng ...
- ggplot2学习总结
- ubuntu没有声音解决办法
cd /usr/lib/dbus-1.0/ chmod +x dbus-daemon-launch-helper sudo gpasswd -a $USER audio sudo killall pu ...