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=" ...
随机推荐
- .net core/.net 使用 CommandLineParser 来标准化地解析命令行
CommandLineParser 是一款用于解析命令行参数的 NuGet 包.你只需要关注你的业务,而命令行解析只需要极少量的配置代码. 本文将介绍如何使用 CommandLineParser 高效 ...
- Redis-cli 命令不能用
bash: redis-cli: command not found... 环境: Linux7.X 在运行redis-cli命令的时候提示错误: 解决方案: 1. wget http://downl ...
- Vue源码探究-数据绑定的实现
Vue源码探究-数据绑定的实现 本篇代码位于vue/src/core/observer/ 在总结完数据绑定实现的逻辑架构一篇后,已经对Vue的数据观察系统的角色和各自的功能有了比较透彻的了解,这一篇继 ...
- cnn.py cs231n
n import numpy as np from cs231n.layers import * from cs231n.fast_layers import * from cs231n.layer_ ...
- web服务器与tomcat
web服务器与tomcat 服务器分类: 硬件服务器和软件服务器 web服务器: 提供资源供别人访问 web: 网页的意思,资源. web资源分类: 动态的web资源:内容有可能发生改变的 静态的we ...
- php rmdir使用递归函数删除非空目录的方法
php rmdir()函数 rmdir ― 删除空目录 语法: bool rmdir ( string $dirname [, resource $context ] )尝试删除 dirname 所指 ...
- Python之collection
1.计数器(counter) Counter是对字典类型的补充,用于追踪值的出现次数. ps:具备字典的所有功能 + 自己的功能 c = Counter('abcdeabcdabcaba') prin ...
- less知识点总结(二)
变量:以@开头,由于变量只能定义一次,其本质就是“常量”. @nice-blue: #5B83AD; @light-blue: @nice-blue + #; #header { color: @li ...
- windows下 python中报错ImportError: No module named 'requests'
原因没有安装requests模块, 可以切换到python的安装目录找到 script文件夹 example: 进入cmd窗口切换到上面的目录直接运营下面两个命令中的一个 1. > Path\p ...
- 移动端以及 PC浏览器页面分享到朋友圈等的功能实现
我们经常可以在一些 app上看到分享到朋友圈.微信好友.qq好友等功能,例如 饿了么.美团等 app,下单之后就会弹出给好友发红包的 modal窗,这在 app上很常见,app的权限可以很大,甚至连启 ...