Example-09-01
#define _CRT_SECURE_NO_WARNINGS #include <cstdio>
#include <cstring> int min(int a, int b)
{
if (a < b) return a;
else return b;
} int main()
{
int N; // 2 <= N <= 50
int t[];
int T; // 0 <= T <= 200
int M1, M2; // 1 <= M1, M2 <= 50
int d[], e[]; int have_train[][][]; // [time][station][direction]
// time <= 200
// sation <= 50
// direction == 0 left, == 1 right int kase = ; while (scanf("%d", &N) && N) {
scanf("%d", &T);
for (int i = ; i < N; i++)
scanf("%d", &t[i]); // t[i] is the time between station i and station i+1 memset(have_train, , sizeof(have_train)); scanf("%d", &M1); for (int i = ; i < M1; i++){ // for each train
int start;
scanf("%d", &start);
have_train[start][][] = ; // station 1
for (int j = ; j < N; j++) { // station 2, 3, 4..., N; j+1 is the station number
// start + t[j] is the time the train arrives at station j+1, also is start time + time from station 1 to station j+1
// t[j] is the time between station j and station j+1
if (start + t[j] <= T) {
have_train[start + t[j]][j + ][] = ;
}
start += t[j];
}
} scanf("%d", &M2);
for (int i = ; i < M2; i++){ // for each train
int start;
scanf("%d", &start);
have_train[start][N][] = ; // station N
for (int j = N-; j >= ; j--) { // station N-1, N-2, ..., 1; j is the station number
// start + t[j] is the time the train arrives at station j, also is start time + time from station N to station j
// t[j] is the time between station j and station j+1
if (start + t[j] <= T) {
have_train[start + t[j]][j][] = ;
}
start += t[j];
}
} #define INF 10000000
int counts = ;
int dp[][]; for (int i = ; i <= N-; i++)
dp[T][i] = INF;
dp[T][N] = ; for (int i = T - ; i >= ; i--){
for (int j = ; j <= N; j++){
dp[i][j] = dp[i+][j] + ;
if (j < N && i + t[j] <= T && have_train[i][j][]){
dp[i][j] = min(dp[i][j], dp[i+t[j]][j+]); // t[j] is the time between station j and station j+1
}
if (j > && i + t[j-] <= T && have_train[i][j][]){
dp[i][j] = min(dp[i][j], dp[i+t[j-]][j-]); // t[j-1] is the time between station j-1 and station j
}
}
} if (dp[][] >= INF)
printf("Case Number %d: impossible\n", ++counts);
else
printf("Case Number %d: %d\n", ++counts, dp[][]); } return ;
}
Example-09-01的更多相关文章
- 调试大叔V1.0.1(2017.09.01)|http/s接口调试、数据分析程序员辅助开发神器
2017.09.01 - 调试大叔 V1.0.1*支持http/https协议的get/post调试与反馈:*可保存请求协议的记录:*内置一批动态参数,可应用于URL.页头.参数:*可自由管理cook ...
- Cheatsheet: 2016 09.01 ~ 09.30
Web Is JavaScript Single-Threaded? Quill 1.0 – Better Rich Text Editor for Web Apps Next Generation ...
- Cheatsheet: 2015 09.01 ~ 09.30
Web A Guide to Vanilla Ajax Without jQuery Gulp for Beginners A Detailed Walkthrough of ASP.net MVC ...
- Cheatsheet: 2014 09.01 ~ 09.30
Mobile Testing Mobile: Emulators, Simulators And Remote Debugging iOS 8 and iPhone 6 for Web Develop ...
- Cheatsheet: 2013 09.01 ~ 09.09
.NET Multi Threaded WebScraping in CSharpDotNetTech .NET Asynchronous Patterns An Overview of Projec ...
- NYOJ-171 聪明的kk AC 分类: NYOJ 2014-01-02 09:01 165人阅读 评论(0) 收藏
#include<stdio.h> #define max(x,y) x>y?x:y int main(){ int num[22][22]={0}; int n,m; int x, ...
- 2016.09.01 html5兼容
<!--[if lt IE 9]> <script src="http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min ...
- 2018.09.01 09:22 Exodus
Be careful when writing in the blog garden. Sometimes you accidentally write something wrong, and yo ...
- 2018.09.01 09:08 Genesis
Nothing to think about, I don't know where to start, the mastery of learning is not an easy task, yo ...
- 2018.09.01 poj3071Football(概率dp+二进制找规律)
传送门 概率dp简单题. 设f[i][j]表示前i轮j获胜的概率. 如果j,k能够刚好在第i轮相遇,找规律可以发现j,k满足: (j−1)>>(i−1)" role=" ...
随机推荐
- WCF 服务
1.代码 using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Seriali ...
- MYSQL监控工具--mytop
https://mp.weixin.qq.com/s/1X_uZaajImRRmpAsdLsNGw mysql可以说如今最为流行的数据库了,虽然现在nosql的风头正盛.但我想很多公司重要的业务数据不 ...
- python fullmatch函数
- spark-ML基础
一.ML组件 ML的标准API使用管道(pipeline)这样的方式,可以将多个算法或者数据处理过程整合到一个管道或者一个流程里运行,其中包含下面几个部分: 1. dataFrame:用于ML的dat ...
- 使用HashMap编写一程序实现存储某班级学生信息
1. 使用HashMap编写一程序实现存储某班级学生信息,要求在屏幕上打印如下列表 学号 姓名 性别 年龄 001 张三 男 23 002 李四 男 ...
- ansible Ansible Galaxy ansible-playbook 安装 使用 命令 笔记 生成密钥 管控机 被管控机 wget epel源
笔记 ansible 安装 与salt对比 相同 都是为了同时在多台机器上执行相同的命令 都是python开发 不同 agent(saltstack需要安装.ansible不需要) 配置(salt配置 ...
- Redis、MPP、kafka 、MongDB简介
Redis :间值数据库,适合缓存用户Session会话与经常需要查的数据1.Redis集群,为什么在项目中使用集群 1.持久化,持久化是最简单的高可用方法(有时甚至不被归为高可用的手段),主要左右 ...
- day002--python编程的相关软件,变量
--python是一门解释型语言,需要安装解释器,由于python3和python不兼容,所以需要安装这两个版本的解释器. 目前python2.7版本已经停止更新,使用企业较少,所以应当以学习pyth ...
- github中markdown语言的使用规则
开始使用github就接触了markdown,确实如它的宗旨所言"易读易写",语法简洁明了,功能比纯文本更强,是一种非常适用于网络的书写语言.并且一大优点是兼容HTML,只要不在m ...
- Java程序中如何使用事物
在java操作数据库是,为了保证数据的一致性,比如转账操作,从一个账户减掉10元,在另一个账户加上10元. 在类中定义的成员属性(变量)不用赋初值,但在函数里头定义的变量就一定要赋初值. packag ...