poj3411 Paid Roads
思路:
搜索。注意点和边都有可能经过多次。
实现:
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int MAXN = , INF = 0x3f3f3f3f;
int n, m;
struct edge
{
int to, c, p, r;
};
vector<edge> G[MAXN];
int vis[MAXN]; int dfs(int now)
{
if (now == n)
return ;
int ans = INF;
for (int i = ; i < G[now].size(); i++)
{
if (vis[G[now][i].to] > ) continue;
vis[G[now][i].to]++;
int x = dfs(G[now][i].to) + G[now][i].r;
ans = min(ans, x);
int y = INF;
if (vis[G[now][i].c])
y = dfs(G[now][i].to) + G[now][i].p;
ans = min(ans, y);
vis[G[now][i].to]--;
}
return ans;
} int main()
{
cin >> n >> m;
int a, b, c, p, r;
for (int i = ; i < m; i++)
{
cin >> a >> b >> c >> p >> r;
G[a].push_back(edge{b, c, p, r});
}
vis[] = true;
int ans = dfs();
if (ans == INF) puts("impossible");
else cout << ans << endl;
return ;
}
poj3411 Paid Roads的更多相关文章
- 【题解】Paid Roads [SP3953] [Poj3411]
[题解]Paid Roads [SP3953] [Poj3411] 传送门:\(\text{Paid}\) \(\text{Roads}\) \(\text{[SP3953]}\) \(\text{[ ...
- 多次访问节点的DFS POJ 3411 Paid Roads
POJ 3411 Paid Roads Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6553 Accepted: 24 ...
- poj 3411 Paid Roads(dfs)
Description A network of m roads connects N cities (numbered to N). There may be more than one road ...
- Paid Roads POJ - 3411
A network of m roads connects N cities (numbered from 1 to N). There may be more than one road conne ...
- POJ 3411 Paid Roads(DFS)
题目链接 点和边 都很少,确定一个界限,爆搜即可.判断点到达注意一下,如果之前已经到了,就不用回溯了,如果之前没到过,要回溯. #include <cstring> #include &l ...
- POJ 3411 Paid Roads(SPFA || DFS)
题目链接 题意 : 要从1城市到n城市,求最短路是多少,从a城市到达b城市的路程,如果你到过c城市,则需要走p,否则走r长. 思路 : 因为可以来回走,所以不能用单纯的最短路,可以用二维SPFA,状态 ...
- poj 3411 Paid Roads
题意:有m条路,n座城市,走这些路是要付费的,每条路由两种付费方案,设一条路两端是a,b,如果走完这条路在b点付费的话,应付r,如果走这条路之前在c点付费的话,应付p,求从1端点走到n端点的最小费用. ...
- poj 3411 Paid Roads很水的DFS
题意:给你N 城市和M条道路,每条道路要付的钱,但是如果你在这个道路上你可以付其他道路的钱(跟走到的时候去的话不一样),问你从1走到N最少话费是多少. 直接DFS搜. 链接http://poj.org ...
- POJ 3411 Paid Roads (状态压缩+BFS)
题意:有n座城市和m(1<=n,m<=10)条路.现在要从城市1到城市n.有些路是要收费的,从a城市到b城市,如果之前到过c城市,那么只要付P的钱, 如果没有去过就付R的钱.求的是最少要花 ...
随机推荐
- 立面图 平面图 剖面图 CAD
http://www.qinxue.com/88.html http://www.xsteach.com/course/2855 前后左右各个侧面的外部投影图——立面图:对建筑物各个侧面进行投影所得到 ...
- Django学习系列之django restframework
曾几何时,Ajax已经统治了Web开发中的客户端,而REST成为web世界中最流行的架构风格(architecture style).所以我们的选择变得很简单:前端ajax访问后端的RESTful A ...
- cocos2d-x+lua开发模式下编辑器的选择
原本打算直接用CocosIDE的,毕竟是官方出品,并且支持Android远程调试,windows下的调试也非常方便,调试的信息也非常全,智能提示也不错.好了,一切看上去非常完美,可是它有一个致命缺陷, ...
- 找了两个node+vue-cli+mogodb的小项目学学
实现的博客系统,自己抽时间搭建看看 https://www.cnblogs.com/yesyes/p/7188331.html https://github.com/chaohangz/vueBlog
- POJ2773 Happy 2006【容斥原理】
题目链接: http://poj.org/problem?id=2773 题目大意: 给你两个整数N和K.找到第k个与N互素的数(互素的数从小到大排列).当中 (1 <= m <= 100 ...
- scikit-learn:3.3. Model evaluation: quantifying the quality of predictions
參考:http://scikit-learn.org/stable/modules/model_evaluation.html#scoring-parameter 三种方法评估模型的预測质量: Est ...
- Fragment进阶(五)----->监听fragment回退事件
activity_main.xml <? xml version="1.0" encoding="utf-8"?> <LinearLayout ...
- vmstat输出项解释
输出项的解释例如以下: procs * r列表示执行和等待cpu时间片段的进程数,这个值假设长期大约系统cpu个数.说明cpu不足 * b列表示在等待资源的进程数.比方正在等待IO或者内存交换等等 m ...
- JavaScriptSerializer 序列号datatime时少了8小时
有人说主要的因素是在于JSON格式不直接支持日期和时间. 简单一点处理办法是ToLocalTime()一下:dt = dt.ToLocalTime(); 参考http://blog.csdn.net/ ...
- [计算机故障]笔记本无法启动,开机启动出现“Operating System Not Found”无法进系统
背景介绍:同事的一台索尼的笔记本,安装XP.开机启动出现“Operating System Not Found”无法进系统 诊断: 初步判断硬盘故障.但听声音,没有异响. 开机按F2进入BIOS设置. ...