Uva1025 A Spy in the Metro
#include <iostream>
#include <cstring>
#include <cstdio> using namespace std; int t[];
int dp[][]; //dp[i][j]记录在第i个车站需要等待时间
int l[][], r[][]; //l[i][j]第i个车站在j时刻是否有从左边行驶的车辆 r[i][j]右方向同l[i][j]
int num = ;
int min(int a,int b){
if(a<b) return a;
return b;
}
int main()
{
int n,T,m,cur;
while (scanf("%d",&n)!=EOF )
{
memset(l, , sizeof(l));
memset(r, , sizeof(r));
memset(dp, 0x3f, sizeof(dp));
cin>>T;
for(int i=;i<n;i++) cin>>t[i];
cin>>m;
for(int i=;i<=m;i++)
{
cin>>cur;
for(int j=;j<=n;j++)
{
l[j][cur] = , cur += t[j];
}
}
cin>>m;
for(int i=;i<=m;i++)
{
cin>>cur;
for(int j=n;j>;j--)
{
r[j][cur] = , cur += t[j - ];
}
}
dp[n][T]=;
for(int j=T-;j>=;j--)
for(int i=;i<=n;i++)
{
dp[i][j]=dp[i][j+]+;
if(l[i][j]) dp[i][j] = min(dp[i][j],dp[i+][j+t[i]]);
if(r[i][j]) dp[i][j] = min(dp[i][j],dp[i-][j+t[i-]]);
}
cout<< "Case Number "<<++num<<": ";
if(dp[][]>T)
cout<<"impossible"<<endl;
else
cout<<dp[][]<<endl;
}
return ;
}
Uva1025 A Spy in the Metro的更多相关文章
- UVA1025 A Spy in the Metro —— DP
题目链接: https://vjudge.net/problem/UVA-1025 题解: 详情请看紫书P267. 与其说是DP题,我觉得更像是模拟题,特别是用记忆化搜索写. 递推: #include ...
- 【动态规划】[UVA1025]A Spy in the Metro 城市里的间谍
参考:https://blog.csdn.net/NOIAu/article/details/71517440 https://blog.csdn.net/c20180630/article/deta ...
- 题解:UVa1025 A Spy in the Metro
原题链接 pdf 题目大意 给出一张无向图图,求该图的最小瓶颈生成树. 无向图的瓶颈生成树:无向图\(G\)的一颗瓶颈生成树是这样的一颗生成树:它最大的边权值在\(G\)的所有生成树中是最小的.瓶颈生 ...
- 【Uva1025 A Spy in the Metro】动态规划
题目描述 某城市地铁是线性的,有n(2≤n≤50)个车站,从左到右编号1~n.有M1辆列车从第1站开始往右开,还有M2辆列车从第n站开始往左开.列车在相邻站台间所需的运行时间是固定的,因为所有列车的运 ...
- 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 1025 A Spy int the Metro
https://vjudge.net/problem/UVA-1025 看见spy忍俊不禁的想起省赛时不知道spy啥意思 ( >_< f[i][j]表示i时刻处于j站所需的最少等待时间,有 ...
随机推荐
- Thinkphp2.1爆出重大安全漏洞
thinkphp 2.1的版本 我们来分析下漏洞吧 官方发布了一个安全补丁 表述是:该URL安全漏洞会造成用户在客户端伪造URL,执行非法代码. 官方的补丁: /trunk/ThinkPHP/Lib/ ...
- vulkan
https://gfxbench.com/device.jsp?benchmark=gfx40&os=Android&api=gl&D=Asus+ZenFone+4+%28Ad ...
- http://www.cnblogs.com/langtianya/archive/2013/02/01/2889682.html
http://www.cnblogs.com/langtianya/archive/2013/02/01/2889682.html
- struts2文件上传时获取上传文件的大小
利用struts2框架上传文件时,如果想要获取上传文件的大小可以利用下面的方式进行: FileInputStream ins = new FileInputStream(file); if (ins. ...
- Yii2系列教程二:MVC,Forms和Layouts
上一篇文章我们简单地实现了Yii2框架安装和Hello World,而在这一篇文章当中,我们会带着好奇之心去探索一下在Yii2中的几个重要的元素组成:MVC,Forms和Layouts. 本文的目标是 ...
- Windows下pip安装scipy报错no lapack/blas resources found
Windows下升级了pandas,但是发现scipy包随后引用出错,后来确认需重新安装scipy, 在用pip安装scipy出现no lapack/blas resources found的错误. ...
- 2017.11.21 查询某个字段为null的记录
注意,不使用 = null, 而是 is null. select fd_username, fd_tenantid, fd_validity from t_user WHERE fd_validit ...
- GBDT,随机森林
author:yangjing ## time:2018-10-22 Gradient boosting decision tree 1.main diea The main idea behind ...
- PHP,mysql,Linux,CI框架学习总结
PHP,mysql,CI框架学习总结 PHP标记 1.Xml风格<?php ?> 2.简短风格 <? ?> 需在php.ini中开启short_open_tag 3.asp风格 ...
- Atitit.木马病毒 webftp 的原理跟个设计
Atitit.木马病毒 webftp 的原理跟个设计 ftp木马的效果 文件传播 文件列表 文件内容查看 作者:: ★(attilax)>>> 绰号:老哇的爪子 ( 全名::Att ...