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=" ...
随机推荐
- Django用户名密码错误提示
from django.shortcuts import render # Create your views here. from django.shortcuts import render fr ...
- django 结合 bootstrap 使用
git clone https://github.com/dyve/django-bootstrap3.git 要运行demo,需要在demo 中为其增加一个符号链接 bootstrap3 到上层目录 ...
- 使用Webpack的代码分离实现Vue懒加载
当一个Vue的项目体积变得十分庞大的时候,使用Webpack的代码分离功能将Vue Components,routes或Vuex的代码进行分离并按需加载,会极大的提高App的首屏加载速度. 在Vue的 ...
- day4new-转自金角大王
Python之路,Day4 - Python基础4 (new版) 本节内容 迭代器&生成器 装饰器 Json & pickle 数据序列化 软件目录结构规范 作业:ATM项目开发 ...
- 纯CSS3个性化圆形按钮登录表单
在线演示 本地下载
- jquery全屏图片滑动切换
在线演示 本地下载
- Selenium-Switch与SelectApi接口
Switch 我们在UI自动化测试时,总会出现新建一个tab页面.弹出一个浏览器级别的弹框或者是出现一个iframe标签,这时我们用WebDriver提供的Api接口就无法处理这些情况了.需要用到Se ...
- java返回结果集封装
1.返回消息统一定义文件CodeMsg.java public class CodeMsg { private int retCode; private String message; // 按照模块 ...
- UIView 判断是否visible
if(self.view == [(MyAppDelegate *)[[UIApplication sharedApplication] delegate].window.subviews objec ...
- jQuery 图片跟着鼠标动
html默认鼠标样式改成图片时格式为 .ani 图片跟随鼠标挪动 html <div id="mouseImg"> <img src="images/问 ...