Journey

题目链接:http://codeforces.com/problemset/problem/721/C

dp/记忆化搜索/拓扑排序

刚开始想到用bfs+dp,fst(然而中间有一步逻辑错了,不得不说pretest真心弱,然后rank一掉回到解放前),改正后MLE了,状态没去重存不下...

看了下其他人的,基本用的是记忆化搜索,复杂度是O(m*n);看了下队友ac的,以为是bfs,问了下回答说是拓扑排序(不会=、=)

游少给了一种直接dp的思路Orz,复杂度是O(m*n):

其中time[i][j]表示经过i个结点到达j结点所需要的时间,

pre[i][j]表示经过i个结点到达j结点前的结点序号。

代码如下:

 #include<cstdio>
#include<stack>
#define N 5005
using namespace std;
struct node{
int u,v,t;
}egde[N];
int time[N][N],pre[N][N];
int n,m,T;
int main(void){
scanf("%d%d%d",&n,&m,&T);
for(int i=;i<=m;++i)
scanf("%d%d%d",&egde[i].u,&egde[i].v,&egde[i].t);
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
time[i][j]=T+;
time[][]=;
for(int i=;i<n;++i)
for(int j=;j<=m;++j){
int u=egde[j].u;
int v=egde[j].v;
int t=egde[j].t;
if(time[i][u]+t<time[i+][v]){
time[i+][v]=time[i][u]+t;
pre[i+][v]=u;
}
}
int floor;
for(int i=n;i>=;--i)
if(time[i][n]<T+){
floor=i;
printf("%d\n",floor);
break;
}
int nod=n;
stack<int>s;
while(pre[floor][nod]){
s.push(pre[floor][nod]);
nod=pre[floor][nod];
floor--;
}
while(!s.empty()){
nod=s.top();
s.pop();
printf("%d ",nod);
}
printf("%d\n",n);
}

Journey的更多相关文章

  1. CF721C. Journey[DP DAG]

    C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard input ou ...

  2. POJ2488A Knight's Journey[DFS]

    A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41936   Accepted: 14 ...

  3. CF #374 (Div. 2) C. Journey dp

    1.CF #374 (Div. 2)    C.  Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...

  4. POJ2488-A Knight's Journey(DFS+回溯)

    题目链接:http://poj.org/problem?id=2488 A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Tot ...

  5. codeforces 721C C. Journey(dp)

    题目链接: C. Journey time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  6. A Knight's Journey 分类: POJ 搜索 2015-08-08 07:32 2人阅读 评论(0) 收藏

    A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35564 Accepted: 12119 ...

  7. HDOJ-三部曲一(搜索、数学)- A Knight's Journey

    A Knight's Journey Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) ...

  8. 【推公式】UVa 10995 - Educational Journey

    1A~,但后来看人家的代码好像又写臭了,T^T... Problem A: Educational journey The University of Calgary team qualified f ...

  9. poj 3544 Journey with Pigs

    Journey with Pigs Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3004   Accepted: 922 ...

  10. HDU 5477 A Sweet Journey 水题

    A Sweet Journey Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

随机推荐

  1. C#调用百度地图API

    1.打开链接http://developer.baidu.com/map/jshome.htm这里有很多DEMO,或者你直接百度搜索"百度地图API",第一个就是.进入后有很多方向 ...

  2. Maven配置插件跳过测试代码的编译和运行

    Maven配置插件跳过测试代码的编译和运行: <!-- 编译插件 --> <plugin> <groupId>org.apache.maven.plugins< ...

  3. Imagine Cup 微软“创新杯”全球学生科技大赛

    一. 介绍 微软创新杯微博:http://blog.sina.com.cn/u/1733906825 官方站点:https://www.microsoft.com/china/msdn/student ...

  4. 【LeetCode】25. Reverse Nodes in k-Group

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k  ...

  5. 我是这样使用template.js来异步渲染数据的

    总监的代码用的是define+module.exports,为了效率先没去了解那一块,在github上找了一款功能单一的template.js来使用 https://github.com/yanhai ...

  6. 动态网站加速,cdn义不容辞

    "双十一"大战已经落下帷幕,各大电商纷纷拿出了亮眼的成绩单,但在这些成绩单的背后,CDN加速技术是功不可没的.随着互联网的发展,电商.视频直播等网站的火热,以及各个云加速平台的流行 ...

  7. HDU 1272 小希的迷宫(乱搞||并查集)

    小希的迷宫 Problem Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有 ...

  8. const 那点事儿

    修饰变量时 const char 与 char const 是等价的,例如 const char a = 'a'; char const a = 'a'; 表示变量a不能再被赋予其他值. 到指针时情况 ...

  9. HC-05与HC-06的AT指令的区别

    蓝牙HC-05与HC-06对比指令集 高电平->AT命令响应工作状态     低电平->蓝牙常规工作状态 <重新上电表示完成复位> HC-05 可以主从切换模式,但是HC-06 ...

  10. es5 中类的2种基本实现方法

    function test(){ this.a = 1; this.func = function(){ // var a = 3;下面的this 取的是上面的1,这个不影响 return this. ...