https://vjudge.net/problem/UVA-1025

看见spy忍俊不禁的想起省赛时不知道spy啥意思 ( >_<

f[i][j]表示i时刻处于j站所需的最少等待时间,有三种可能,一是i-1时刻就在这里然后等待了1时刻  f[i][j]=f[i-1][j]+1  ; 二是正好由由左边相邻的一个车站开过来(如果可以的话)  f[i][j]=f[i-t[j-1]][j-1];  三是正好由右边的车站开过来(if can) f[i][j]=f[i-t[j]][j+1]; 取三者的最小值就好,最后如果f[T][N]>=inf表示impossible.

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define inf 0x3f3f3f3f
  4. int t[],tl[],tr[];
  5. int f[][];
  6. bool can[][][];
  7. int main()
  8. {
  9. int N,T,M1,M2,i,j,k=;
  10. while(cin>>N&&N){
  11. cin>>T;
  12. for(i=;i<N;++i) scanf("%d",t+i);
  13. memset(f,inf,sizeof(f));
  14. memset(can,,sizeof(can));
  15. cin>>M1;
  16. for(i=;i<=M1;++i)
  17. {
  18. int s;
  19. scanf("%d",tl+i);
  20. for(j=,s=tl[i];j<=N&&s<=T;s+=t[j++])
  21. {
  22. can[s][j][]=;
  23. }
  24. }
  25. cin>>M2;
  26. for(i=;i<=M2;++i)
  27. {
  28. int s;
  29. scanf("%d",tr+i);
  30. for(j=N,s=tr[i];j>=&&s<=T;s+=t[j-],j--)
  31. can[s][j][]=;
  32. }
  33. f[][]=;
  34. for(i=;i<=T;++i)
  35. {
  36. for(j=;j<=N;++j)
  37. {
  38. f[i][j]=f[i-][j]+;
  39. if(j>&&i-t[j-]>=&&can[i-t[j-]][j-][])
  40. f[i][j]=min(f[i][j],f[i-t[j-]][j-]);
  41. if(j<N&&i-t[j]>=&&can[i-t[j]][j+][])
  42. f[i][j]=min(f[i][j],f[i-t[j]][j+]);
  43. }
  44. }
  45. printf("Case Number %d: ",++k);
  46. if(f[T][N]>=inf) puts("impossible");
  47. else cout<<f[T][N]<<endl;
  48. }
  49. return ;
  50. }
  51. /*
  52. 4
  53. 55
  54. 5 10 15
  55. 4
  56. 0 5 10 20
  57. 4
  58. 0 5 10 15
  59.  
  60. ans=5
  61. */

uva 1025 A Spy int the Metro的更多相关文章

  1. UVA - 1025 A Spy in the Metro[DP DAG]

    UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especia ...

  2. UVA 1025 -- A Spy in the Metro (DP)

     UVA 1025 -- A Spy in the Metro  题意:  一个间谍要从第一个车站到第n个车站去会见另一个,在是期间有n个车站,有来回的车站,让你在时间T内时到达n,并且等车时间最短, ...

  3. uva 1025 A Spy in the Metro 解题报告

    A Spy in the Metro Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug Secr ...

  4. UVa 1025 A Spy in the Metro(动态规划)

    传送门 Description Secret agent Maria was sent to Algorithms City to carry out an especially dangerous ...

  5. UVA 1025 A Spy in the Metro 【DAG上DP/逆推/三维标记数组+二维状态数组】

    Secret agent Maria was sent to Algorithms City to carry out an especially dangerous mission. After s ...

  6. UVa 1025 A Spy in the Metro

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35913 预处理出每个时间.每个车站是否有火车 为了方便判断是否可行,倒推处理 ...

  7. DAG的动态规划 (UVA 1025 A Spy in the Metro)

    第一遍,刘汝佳提示+题解:回头再看!!! POINT: dp[time][sta]; 在time时刻在车站sta还需要最少等待多长时间: 终点的状态很确定必然是的 dp[T][N] = 0 ---即在 ...

  8. World Finals 2003 UVA - 1025 A Spy in the Metro(动态规划)

    分析:时间是一个天然的序,这个题目中应该决策的只有时间和车站,使用dp[i][j]表示到达i时间,j车站在地上已经等待的最小时间,决策方式有三种,第一种:等待一秒钟转移到dp[i+1][j]的状态,代 ...

  9. UVa 1025 A Spy in the Metro (DP动态规划)

    题意:一个间谍要从第一个车站到第n个车站去会见另一个,在是期间有n个车站,有来回的车站,让你在时间T内时到达n,并且等车时间最短, 也就是尽量多坐车,最后输出最少等待时间. 析:这个挺复杂,首先时间是 ...

随机推荐

  1. 查看hive的配置信息

    在启动hive时设置配置属性信息 $ bin/hive --hiveconf <property=value> 查看当前所有的配置信息 hive > set ; hive (db_h ...

  2. highcharts基本介绍

    转自:http://www.cnblogs.com/jyh317/p/4189773.html 一.highcharts简介 Highcharts是一款纯javascript编写的图表库,能够很简单便 ...

  3. Loadrunder之脚本篇——参数化方法

    导语 参数化旨在模拟多数据来进行测试,所以再选择参数化你明确你参数化的内容! 方法一 1.确定需要参数化的内容 2.选中需要参数化的内容 3.右键选中的内容->Replace with a Pa ...

  4. webbrowser控件——Windows下的开发利器

    首先说明,本人比较菜,做C++没多长时间. 刚开始用MFC写程序时,连个基本的字体都不会变(颜色.大小等), 索性干脆就啥也不改了,直接默认,界面就那样了,老子不管了. 心想这C++做个界面咋就那么麻 ...

  5. InnoDB存储引擎内存缓冲池管理技术——LRU List、Free List、Flush List

    InnoDB是事务安全的MySQL存储引擎,野山谷OLTP应用中核心表的首选存储引擎.他是基于表的存储引擎,而不是基于数据库的.其特点是行锁设计.支持MVCC.支持外键.提供一致性非锁定读,同时被设计 ...

  6. Linux Shell基础 环境变量

    环境变量 环境变量和用户自定义变量最主要的区别在于,环境变量是全局变量,而用户自定义变量是局部变量.用户自定义变量只在当前的 Shell 中生效,而环境变量会在当前 Shell 和这个 Shell 的 ...

  7. 【leetcode刷题笔记】Number of 1 Bits

    Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...

  8. 20145231 《Java程序设计》第一周学习总结

    20145231 <Java程序设计>第一周学习总结 教材学习内容总结 Java三大平台Java SE,Java EE,Java ME.其中,Java SE是我们学习的基础. Java S ...

  9. 20145240 《Java程序设计》第一次实验报告

    20145240 <Java程序设计>第一次实验报告 实验内容 一.命令行下java程序开发 1.建立Code目录,输入mkdir 20145240命令建立实验目录,并使用dir命令查看目 ...

  10. nginx location proxy pass

    nginx: 192.168.1.23作为nginx反向代理机器 目标机器192.168.1.5上部署一个8090端口的nginx [root@localhost conf.d]# cat test. ...