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,并且等车时间最短, 也就是尽量多坐车,最后输出最少等待时间. 析:这个挺复杂,首先时间是 ...
随机推荐
- 查看hive的配置信息
在启动hive时设置配置属性信息 $ bin/hive --hiveconf <property=value> 查看当前所有的配置信息 hive > set ; hive (db_h ...
- highcharts基本介绍
转自:http://www.cnblogs.com/jyh317/p/4189773.html 一.highcharts简介 Highcharts是一款纯javascript编写的图表库,能够很简单便 ...
- Loadrunder之脚本篇——参数化方法
导语 参数化旨在模拟多数据来进行测试,所以再选择参数化你明确你参数化的内容! 方法一 1.确定需要参数化的内容 2.选中需要参数化的内容 3.右键选中的内容->Replace with a Pa ...
- webbrowser控件——Windows下的开发利器
首先说明,本人比较菜,做C++没多长时间. 刚开始用MFC写程序时,连个基本的字体都不会变(颜色.大小等), 索性干脆就啥也不改了,直接默认,界面就那样了,老子不管了. 心想这C++做个界面咋就那么麻 ...
- InnoDB存储引擎内存缓冲池管理技术——LRU List、Free List、Flush List
InnoDB是事务安全的MySQL存储引擎,野山谷OLTP应用中核心表的首选存储引擎.他是基于表的存储引擎,而不是基于数据库的.其特点是行锁设计.支持MVCC.支持外键.提供一致性非锁定读,同时被设计 ...
- Linux Shell基础 环境变量
环境变量 环境变量和用户自定义变量最主要的区别在于,环境变量是全局变量,而用户自定义变量是局部变量.用户自定义变量只在当前的 Shell 中生效,而环境变量会在当前 Shell 和这个 Shell 的 ...
- 【leetcode刷题笔记】Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...
- 20145231 《Java程序设计》第一周学习总结
20145231 <Java程序设计>第一周学习总结 教材学习内容总结 Java三大平台Java SE,Java EE,Java ME.其中,Java SE是我们学习的基础. Java S ...
- 20145240 《Java程序设计》第一次实验报告
20145240 <Java程序设计>第一次实验报告 实验内容 一.命令行下java程序开发 1.建立Code目录,输入mkdir 20145240命令建立实验目录,并使用dir命令查看目 ...
- nginx location proxy pass
nginx: 192.168.1.23作为nginx反向代理机器 目标机器192.168.1.5上部署一个8090端口的nginx [root@localhost conf.d]# cat test. ...