#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的更多相关文章

  1. 调试大叔V1.0.1(2017.09.01)|http/s接口调试、数据分析程序员辅助开发神器

    2017.09.01 - 调试大叔 V1.0.1*支持http/https协议的get/post调试与反馈:*可保存请求协议的记录:*内置一批动态参数,可应用于URL.页头.参数:*可自由管理cook ...

  2. Cheatsheet: 2016 09.01 ~ 09.30

    Web Is JavaScript Single-Threaded? Quill 1.0 – Better Rich Text Editor for Web Apps Next Generation ...

  3. Cheatsheet: 2015 09.01 ~ 09.30

    Web A Guide to Vanilla Ajax Without jQuery Gulp for Beginners A Detailed Walkthrough of ASP.net MVC ...

  4. Cheatsheet: 2014 09.01 ~ 09.30

    Mobile Testing Mobile: Emulators, Simulators And Remote Debugging iOS 8 and iPhone 6 for Web Develop ...

  5. Cheatsheet: 2013 09.01 ~ 09.09

    .NET Multi Threaded WebScraping in CSharpDotNetTech .NET Asynchronous Patterns An Overview of Projec ...

  6. 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, ...

  7. 2016.09.01 html5兼容

    <!--[if lt IE 9]>  <script src="http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min ...

  8. 2018.09.01 09:22 Exodus

    Be careful when writing in the blog garden. Sometimes you accidentally write something wrong, and yo ...

  9. 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 ...

  10. 2018.09.01 poj3071Football(概率dp+二进制找规律)

    传送门 概率dp简单题. 设f[i][j]表示前i轮j获胜的概率. 如果j,k能够刚好在第i轮相遇,找规律可以发现j,k满足: (j−1)>>(i−1)" role=" ...

随机推荐

  1. java中的线程(2):如何正确停止线程之2种常见停止方式

    1.常见停止方式 结束run函数,run中含退出标志位. 使用interrupt()方法中断线程 使用stop方法暴力终止(已经弃用) 2.结束run class TestThread extends ...

  2. ML面试1000题系列(41-50)

    本文总结ML面试常见的问题集 转载来源:https://blog.csdn.net/v_july_v/article/details/78121924 41. #include和#include“fi ...

  3. web前端学习(四)JavaScript学习笔记部分(4)-- JavaScriptDOM对象

    1.Javascript-DOM简介 1.1.HTML DOM 1.2.DOM操作HTML 1.2.1.JavaScript能够改变页面中的所有HTML元素 1.2.2.JavaScript能够改变页 ...

  4. POJ 2311 博弈

    #include<stdio.h> #include<string.h> #include<set> using namespace std; ][]; int s ...

  5. 在一个已经使用mybatis的项目里引入mybatis-plus,结果不能共存

    mybatis-plus版本号:3.0.6 问题产生原因: 原有的项目使用的是springboot+mybatis的框架,一切接口服务均没有问题.由于新的需求增加shiro权限认证,然后也在考虑用my ...

  6. Leetcode3.Longest Substring Without Repeating Characters无重复字符的最长字串

    给定一个字符串,找出不含有重复字符的最长子串的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 无重复字符的最长子串是 "abc",其长度为 ...

  7. Eslint报错的翻译

    若在git中出现这个 http://eslint.org/docs/rules/eol-last 他是提醒你:在文件末尾要求或禁止换行 比如代码如下: 若在git中出现这个 https://eslin ...

  8. es6 babel转码器安装配置及常见命令

    示例:在d盘,新建文件夹es6,文件夹里新建一个文件es6.js. (1)先全局安装babel-cli,输入命令npm install babel-cli -g (2)输入d:( 进入d盘),再输入c ...

  9. php 如何生成静态页

    PHP文件名:dome.php <?php $string = 1; ob_start(); @readfile("templets/list.html"); $text = ...

  10. 19-2 from和modelform的用法和介绍

    一 form 1. form的作用 1. 生成HTML代码 2. 帮我们做数据有效性的校验 3. 保留上次输入内容,显示错误提示 2. form组件校验数据有效性   1. 内置的校验规则 1. re ...