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实现密码加密的注册(数据对象插入)
在 django实现密码非加密的注册(数据对象插入)的基础上,我们对视图和注册页面进行了简单修改 视图 from django.shortcuts import render,redirect,ren ...
- Ubuntu系统下完全卸载和安装Mysql
删除 mysql sudo apt-get autoremove --purge mysql-server-5.0 sudo apt-get remove mysql-server sudo apt- ...
- (4.11)DBCC 常用命令
三.DBCC状态.验证.其他语句 跟踪标识全集:https://www.cnblogs.com/lyhabc/articles/4092507.html 状态语句DBCC INPUTBUFFER 显示 ...
- sql server监控图解
- android开发 软键盘出现后 防止EditText控件遮挡 总体平移UI
在EditText控件接近底部的情况下 软键盘弹出后会把获得焦点的EditText控件遮挡 无法看到输入信息 防止这种情况发生 就须要设置AndroidManifest.xml的属性 前面的xml信 ...
- springMVC文件的上传与下载
1.文件上传 springmvc中只需要配置上传组件,然后配合使用MultipartFile,就可以轻松实现单个文件上传和批量上传,而且上传的文件类型和大小都可以在springmvc 配置文件中配置. ...
- Android Studio工程引用第三方so文件
应用程序二进制接口(Application Binary Interface)定义了二进制文件(尤其是.so文件)如何运行在相应的系统平台上,从使用的指令集,内存对齐到可用的系统函数库.在Androi ...
- LeetCode-day03
28. Best Time to Buy and Sell Stock 买卖股票的最好时间 29. Best Time to Buy and Sell Stock II 买卖股票2(多次买入,一次卖出 ...
- 常用模块之hashlib,configparser,logging模块
常用模块二 hashlib模块 hashlib提供了常见的摘要算法,如md5和sha1等等. 那么什么是摘要算法呢?摘要算法又称为哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固定 ...
- mssql 中文乱码 字库集 问题解决方法
The database could not be exclusively locked to perform the operation(SQL Server 5030错误解决办法) SQL S ...