poj 1274
来源:互联网 发布:js将换行符替换 编辑:程序博客网 时间:2024/06/05 18:17
Description
N cities named with numbers 1 ... N are connected with one-way roads. Each road has two parameters associated with it : the road length and the toll that needs to be paid for the road (expressed in the number of coins).
Bob and Alice used to live in the city 1. After noticing that Alice was cheating in the card game they liked to play, Bob broke up with her and decided to move away - to the city N. He wants to get there as quickly as possible, but he is short on cash.
We want to help Bob to find the shortest path from the city 1 to the city N that he can afford with the amount of money he has.
Bob and Alice used to live in the city 1. After noticing that Alice was cheating in the card game they liked to play, Bob broke up with her and decided to move away - to the city N. He wants to get there as quickly as possible, but he is short on cash.
We want to help Bob to find the shortest path from the city 1 to the city N that he can afford with the amount of money he has.
Input
The first line of the input contains the integer K, 0 <= K <= 10000, maximum number of coins that Bob can spend on his way.
The second line contains the integer N, 2 <= N <= 100, the total number of cities.
The third line contains the integer R, 1 <= R <= 10000, the total number of roads.
Each of the following R lines describes one road by specifying integers S, D, L and T separated by single blank characters :
Notice that different roads may have the same source and destination cities.
The second line contains the integer N, 2 <= N <= 100, the total number of cities.
The third line contains the integer R, 1 <= R <= 10000, the total number of roads.
Each of the following R lines describes one road by specifying integers S, D, L and T separated by single blank characters :
- S is the source city, 1 <= S <= N
- D is the destination city, 1 <= D <= N
- L is the road length, 1 <= L <= 100
- T is the toll (expressed in the number of coins), 0 <= T <=100
Notice that different roads may have the same source and destination cities.
Output
The first and the only line of the output should contain the total length of the shortest path from the city 1 to the city N whose total toll is less than or equal K coins.
If such path does not exist, only number -1 should be written to the output.
If such path does not exist, only number -1 should be written to the output.
Sample Input
5671 2 2 32 4 3 33 4 2 41 3 4 14 6 2 13 5 2 05 4 3 2
Sample Output
11
切水题,邻接表建图
#include<cstdio>#include<iostream>#include<cstring>using namespace std;#define inf 0x3f3f3f3fint n,k,r,ml;int vis[105],h[105];struct edge{ int u,v,l,c,next;}ro[100010];void dfs(int u,int l,int co){ int i; if(l>ml) return ; if(l<ml&&u==n) { ml=l;return ; } for(i=h[u];i!=-1;i=ro[i].next) { if(!vis[ro[i].v]&&co>=ro[i].c) { vis[ro[i].v]=1; dfs(ro[i].v,l+ro[i].l,co-ro[i].c); vis[ro[i].v]=0; } }}int main(){ int i,j; while(~scanf("%d%d%d",&k,&n,&r)) { memset(h,-1,sizeof h); memset(vis,0,sizeof vis); for(i=0;i<r;i++) { scanf("%d%d%d%d",&ro[i].u,&ro[i].v,&ro[i].l,&ro[i].c); ro[i].next=h[ro[i].u]; h[ro[i].u]=i; } ml=inf; dfs(1,0,k); if(ml==inf) printf("-1\n"); else printf("%d\n",ml); } return 0;}
0 0
- poj 1274
- poj 1274
- poj 1274
- poj 1274
- poj 1274
- poj 1274
- POJ 1274 / POJ 1469 / POJ 2239 二分图最大匹配
- poj 2446 poj 1469 poj 1274 二分图最大匹配
- poj 1274(二分匹配)
- POJ 1274 匈牙利算法
- POJ 1274解题报告
- POJ 1274 解题报告
- 匈牙利算法POJ 1274
- POJ 1274 Stall
- POJ
- poj
- POJ
- POJ
- P4
- QT Demo 之 window
- BestCoder Round #19。。。我是个2XXXXX。
- 1163
- 栈和队列的实验
- poj 1274
- hdu-1902 The Dragon of Loowater
- 容器 用Map接口 的 键—值计数
- 【阅读】《head first jquery》第八章——jquery与ajax(让你的页面悄悄的刷新吧)
- 大头锻炼日记1 -- vbscript实现典型线性表
- 养生论-嵇康
- 权限系统——初识
- 通过memcache动态运行库操作memcached服务,进行CURD
- hdu 1059 Dividing (多重背包)