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,并且等车时间最短, 也就是尽量多坐车,最后输出最少等待时间. 析:这个挺复杂,首先时间是 ...
随机推荐
- django实现密码非加密的注册(数据对象插入)
数据模型 from django.db import models class userinfo(models.Model): username = models.CharField(max_leng ...
- Linux查找命令find、locate、whereis、which、type
find:查找指定下目录的文件 -empty:查找空文件 -name:按名字查找 -type f(文件 or d:目录):按类型查找
- git学习------>git commit命令的默认编辑器的修改
今天在新同事的电脑上,用git commit命令帮新同事提交代码的时候,编辑完commit的信息后,居然不记得怎么退出了.蛋疼. 后来百度了一下,原来此时是进入GUN nano编辑器.在这里可以添加你 ...
- 协程 Gevent
# 协程应用:爬虫 from gevent import monkey;monkey.patch_all() import gevent import requests import time def ...
- vue 项目 npm install 报错解决
node-sass 安装报错解决办法 2017年04月15日 14:34:25 阅读数:20189 E:\kibana>npm install node-sass > node-sass@ ...
- Hexo+yilia博客首页不显示全文,显示more,截断文章。
个人主页:https://www.yuehan.online hexo new “xxx” 在md文档中 插入<!--more-->即可. 现在博客:www.wangyurui.top
- hadoop linux 杂记
切换到root su 修改sudo sudo + 命令 --> root权限 + 命令 su root vim /etc/sudoers ...
- 前端 初级篇(CSS)
CSS 简介 css是英文Cascading Style Sheets的缩写,称为层叠样式表,用于对页面进行美化. 存在方式有三种:元素内联.页面嵌入和外部引入,比较三种方式的优缺点. 语法:styl ...
- javascript;先弹出提示框,再跳转到其他页面。
context.Response.Write("<script>alert('删除成功!" + r.ToString() + "条');window.loca ...
- Docker容器技术-Docker架构
一.Docker系统架构 1.Docker基础架构 1)Docker守护进程 负责容器的创建.运行和监控,以及镜像的构建和存储. docker daemon 2)Docker客户端 通过HTTP与Do ...