poj3411 Paid Roads】的更多相关文章

思路: 搜索.注意点和边都有可能经过多次. 实现: #include <iostream> #include <cstdio> #include <vector> using namespace std; , 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…
[题解]Paid Roads [SP3953] [Poj3411] 传送门:\(\text{Paid}\) \(\text{Roads}\) \(\text{[SP3953]}\) \(\text{[Poj3411]}\) [题目描述] 给出一张 \(n\) 个点 \(m\) 条边的有向图.对于每条边 \((x,y)\),如果之前经过 \(z\) 点,那么费用为 \(p\),否则为 \(r\).求 \(1\) 到 \(n\) 的最小费用.如果无法到达则输出 " \(\text{impossibl…
POJ 3411 Paid Roads Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6553   Accepted: 2430 Description A network of m roads connects N cities (numbered from 1 to N). There may be more than one road connecting one city with another. Some o…
Description A network of m roads connects N cities (numbered to N). There may be more than one road connecting one city with another. Some of the roads are paid. There are two ways to pay for travel on a paid road i from city ai to city bi: in advanc…
A network of m roads connects N cities (numbered from 1 to N). There may be more than one road connecting one city with another. Some of the roads are paid. There are two ways to pay for travel on a paid road i from city ai to city bi: in advance, in…
题目链接 点和边 都很少,确定一个界限,爆搜即可.判断点到达注意一下,如果之前已经到了,就不用回溯了,如果之前没到过,要回溯. #include <cstring> #include <cstdio> #include <string> #include <iostream> #include <algorithm> #include <vector> #include <queue> using namespace st…
题目链接 题意 : 要从1城市到n城市,求最短路是多少,从a城市到达b城市的路程,如果你到过c城市,则需要走p,否则走r长. 思路 : 因为可以来回走,所以不能用单纯的最短路,可以用二维SPFA,状态压缩一下,第二维来记录状态,表示到过这个点的第几个状态.也可以用DFS,因为最多十个点,所以如果走某一个点走过三遍说明就是真的只增加费用了,也就是真正的在走环路了.DFS分析 二维SPFA #include <stdio.h> #include <string.h> #include…
题意:有m条路,n座城市,走这些路是要付费的,每条路由两种付费方案,设一条路两端是a,b,如果走完这条路在b点付费的话,应付r,如果走这条路之前在c点付费的话,应付p,求从1端点走到n端点的最小费用. DFS 刚开始想到了用搜索,自己搜索学的不好,有几个问题解决不了,首先就是每个点可以走多次,不能用0,1标记一个点是否走过,如果不标记就可能在一直走一条循环路,还有就是不会回溯,总之,自己就是不会写... 网上抄的别人的代码,每个点最多可以走3次,回溯也挺简单... #include<stdio.…
题意:给你N 城市和M条道路,每条道路要付的钱,但是如果你在这个道路上你可以付其他道路的钱(跟走到的时候去的话不一样),问你从1走到N最少话费是多少. 直接DFS搜. 链接http://poj.org/problem?id=3411 代码: #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <stdlib.h> #inc…
题意:有n座城市和m(1<=n,m<=10)条路.现在要从城市1到城市n.有些路是要收费的,从a城市到b城市,如果之前到过c城市,那么只要付P的钱, 如果没有去过就付R的钱.求的是最少要花多少钱. 析:BFS,然后由于走的路线不同,甚至边或者点都可能多走,所以用状态压缩.然后本题有坑啊,有重连,而且有很多条重边,所以多走几次就好了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include…