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=" ...
随机推荐
- Freckles (最小生成树)
#include<iostream> #include<cstring> #include<stdio.h> #include<queue> #incl ...
- 数据挖掘python,java
互联网公司zamplus诚聘以下职位: (1)数据挖掘工程师 (Location:上海.北京) 岗位职责: 1. 研究基于sponsored search, content match和behavio ...
- 一.JDBC学习入门
一.JDBC相关概念介绍 1.1.数据库驱动 这里的驱动的概念和平时听到的那种驱动的概念是一样的,比如平时购买的声卡,网卡直接插到计算机上面是不能用的,必须要安装相应的驱动程序之后才能够使用声卡和网卡 ...
- R语言与非参数统计(核密度估计)
R语言与非参数统计(核密度估计) 核密度估计是在概率论中用来估计未知的密度函数,属于非参数检验方法之一,由Rosenblatt (1955)和Emanuel Parzen(1962)提出,又名Parz ...
- springboot(十九)使用actuator监控应用【转】【补】
springboot(十九)使用actuator监控应用 微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的 ...
- Oracle之PL/SQL编程
PL/SQL(Procedural Language/SQL,过程语言/SQL) 是结合了Oracel过程语言和结构化查询语言(SQL)的一种扩展语言. 优点: (1)PL/SQL具有编程语言的特点, ...
- More Effective C++: 06杂项讨论
32:在未来时态下发展程序 世事永远在变,好的软件对于变化有良好的适应能力:可以容纳新的性质,可以移植到新的平台,可以适应新的需求,可以掌握新的输入.所谓在未来时态下设计程序,就是接受“事情总会改变” ...
- sqlplus连接数据库报错SP2-0642: SQL*Plus internal error state 2130, context 0:0:0解决
sqlplus连接数据库报错SP2-0642: SQL*Plus internal error state 2130, context 0:0:0解决 sqlplus 连接数据库报错SP2-0642: ...
- GCD使用经验与技巧浅谈
前言 GCD(Grand Central Dispatch)可以说是Mac.iOS开发中的一大“利器”,本文就总结一些有关使用GCD的经验与技巧. dispatch_once_t必须是全局或stati ...
- QT_OPENGL-------- 1. WINDOW
opengl学习第一步,首先来实现一个显示窗口. 1.首先要下载配置glfw,我在前面的文章中也提到过,具体作用可以另行百度.配置出现无法引用可参考ubuntu 使用glfw.h 出现函数无法调用. ...