计蒜客 Skiing
来源:互联网 发布:淘宝客软文推广 编辑:程序博客网 时间:2024/06/05 21:06
题意:
求最长路,记忆化搜索。
In this winter holiday, Bob has a plan for skiing at the mountain resort.
This ski resort has M different ski paths and N different flags situated at those turning points.
The i-th path from the Si-th flag to the Ti-th flag has length Li.
Each path must follow the principal of reduction of heights and the start point must be higher than the end point strictly.
An available ski trail would start from a flag, passing through several flags along the paths, and end at another flag.
Now, you should help Bob find the longest available ski trail in the ski resort.
Input Format
The first line contains an integer T, indicating that there are T cases.
In each test case, the first line contains two integers N and M where 0<N≤10000 and 0<M≤100000 as described above.
Each of the following M lines contains three integers Si, Ti, and Li (0<Li<1000) describing a path in the ski resort.
Output Format
For each test case, ouput one integer representing the length of the longest ski trail.
样例输入
15 41 3 32 3 43 4 13 5 2
样例输出
6
题目来源
2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛
#include<iostream>#include<vector>#include<algorithm>#include<cstdio>#include<cstring>#include<queue>using namespace std;struct node{ int next,dist; node(int a,int b){next=a,dist=b;}};int num[10005];vector<node>G[10005];int dfs(int x){ if(num[x]) return num[x]; for(int i=0;i<G[x].size();i++) { int nx=G[x][i].next,dis=G[x][i].dist; num[x]=max(num[x],dis+dfs(nx)); } return num[x];}int main(){ int t; int n,m; int a,b,c; scanf("%d",&t); while(t--) { memset(num,0,sizeof(num)); scanf("%d%d",&n,&m); for(int i=0;i<=n;i++) G[i].clear(); while(m--) { scanf("%d%d%d",&a,&b,&c); G[a].push_back(node(b,c)); } int ans=0; for(int i=1;i<=n;i++) ans=max(ans,dfs(i)); printf("%d\n",ans); } return 0;}
- 计蒜客 Skiing
- 计蒜客 Skiing 最长路
- Skiing
- skiing
- skiing
- skiing
- Skiing
- Skiing
- Skiing
- skiing
- skiing
- skiing
- skiing
- skiing
- skiing
- Skiing
- skiing
- noj skiing
- 题目372-巧克力
- tablay fragment viewpaper
- HTML2.z
- 性能调优第二篇-执行计划
- Neplan v5.5.8 1CD+Magus Antennamagus v1.0 1CD(天线设计)
- 计蒜客 Skiing
- java集合
- uva1600 (bfs迷宫)
- mybatis自动生成器的配置和使用方法
- 嵌入式软件工程师/linux c程序员 面试经验总结
- 王爽 《汇编语言》 读书笔记 十二 内中断
- 包含min函数的栈java实现
- leetcode 564. Find the Closest Palindrome(java)
- 学习操作系统的进度(2)