[UvaLive 6756] Increasing Shortest Path [动态规划]
来源:互联网 发布:mysql存储过程怎么用 编辑:程序博客网 时间:2024/05/17 02:33
Root ::Regionals 2013 :: Africa/Middle East - Arab Contest 6756 - Increasing Shortest Path
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=592&page=show_problem&problem=4768
给一个图,n个点m条边,q次询问,求从i到j的走过条数不超过c的最短路的长度,走路的时候过的边的长度必须是不减的
数据范围:150点,3000边,1000次询问,时间要求30秒
定义dp[i][j][k]为从i到j,恰好走k次路的最短距离,然后把边排序,逐一添加即可
#include <cstdio>#include <algorithm>#include <cstring>using namespace std;struct Edge {int x,y,z;void read() {scanf("%d%d%d",&x,&y,&z);}friend bool operator < (const Edge &a,const Edge &b) {return a.z<b.z;}};Edge a[3000];int dp[151][151][151];int n,m,q;inline void update(int &a,int b) {if (a==-1||a>b) a=b;}int main() {int t,i,x,y,z,j,k;scanf("%d",&t);while (t--) {scanf("%d%d%d",&n,&m,&q);memset(dp,-1,sizeof(dp));for (i=1;i<=n;i++) dp[i][i][0]=0;for (i=0;i<m;i++) {a[i].read();}sort(a,a+m);for (k=0;k<m;k++) {x=a[k].x; y=a[k].y; z=a[k].z;for (i=1;i<=n;i++) {for (int l=1;l<n;l++)if (dp[i][x][l-1]!=-1) update(dp[i][y][l],dp[i][x][l-1]+z);}}for (i=0;i<q;i++) {scanf("%d%d%d",&x,&y,&k);if (k>=n) k=n-1;int ans=-1;for (int l=0;l<=k;l++) if (dp[x][y][l]!=-1) update(ans,dp[x][y][l]);printf("%d\n",ans);}}return 0;}
0 0
- [UvaLive 6756] Increasing Shortest Path [动态规划]
- hdu 2224 The shortest path 题解(动态规划)
- [HDOJ 4871] Shortest-path tree [树的分治+动态规划]
- SPOJ ACPC13——Increasing Shortest Path
- pku1239 Increasing Sequences (动态规划)
- hdu 2224 The shortest path 双调欧几里得旅行商问题(动态规划)
- 【最短路->DP】SPOJ(ACPC13)[Increasing Shortest Path]题解
- UVALive 6680-动态规划dp
- UVALive - 7527 Funfair (动态规划)
- UVALive 5737|Pills|动态规划
- 334. Increasing Triplet Subsequence 动态规划
- 动态规划-Greatest Common Increasing Subsequence
- leetcode-300-Longest Increasing Subsequence 动态规划
- 动态规划-300. Longest Increasing Subsequence
- 1046. Shortest Distance (20)(动态规划)
- Shortest Path
- Shortest Path
- Shortest Path
- poj1185 状态dp
- 修改数据库文件存放路径的方法
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第2章节--SharePoint 2013 App 模型概览 SharePoint 2013 App 模型
- Goldjengate-如何查看OGG进程已无延迟
- 安卓错误总结
- [UvaLive 6756] Increasing Shortest Path [动态规划]
- android mkdirs()不能创建目录
- java编程题经典中的经典
- Cocos2d-x 3.1 修改程序名、图标和屏幕方向
- 使用struts2和poi导出excel文档
- 给年轻的工程师---关于高工资
- ZOJ-1203
- JavaScript中获取当前项目的绝对路径
- 国家气象局提供的天气预报接口(完整Json接口)