poj2686 Traveling by Stagecoach】的更多相关文章

                http://poj.org/problem?id=2686                                                  Traveling by Stagecoach Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2276   Accepted: 787   Special Judge Description Once upon a time, th…
POJ2686 比较简单的 状态压缩DP 注意DP方程转移时,新的状态必然数值上小于当前状态,故最外层循环为状态从大到小即可. #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int maxn = 1 << 10; const int maxm = 31; const int INF = 1 << 29; int n, m,…
题目大概是给一张有向图,有n张票,每张票只能使用一次,使用一张票就能用pi匹马拉着走过图上的一条边,走过去花的时间是边权/pi,问从a点走到b点的最少时间是多少. 用dp[u][S]表示当前在u点且用过的票集合是S的最少时间,丢进SPFA更新. #include<cstdio> #include<cstring> #include<queue> using namespace std; #define INF 1e8 #define MAXN 33 #define MA…
题意: m个城市, n张车票, 每张车票$t_i$匹马, 每张车票可以沿某条道路到相邻城市, 花费是路的长度除以马的数量. 求a到b的最小花费, 不能到达输出Impossible $1\le n\le8$ $2\le m\le30$ #include <cstdio> #include <cstdlib> #include <cstring> #include <climits> #include <cctype> #include <cm…
状压DP裸题,将({当前车票集合},当前顶点)这样一个二元组当成状态,然后 边权/马匹 当成边长,跑最短路或者DAG上的DP即可. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef double db; #define INF 2147483647.0 int n,m,K,Sta,End; int hor[9]; int e,v[1801],first[…
题意: 有一个旅行家计划乘马车旅行.他所在的国家里共有m个城市,在城市之间有若干道路相连.从某个城市沿着某条道路到相邻的城市需要乘坐马车.而乘坐马车需要使用车票,每用一张车票只可以通过一条道路.每张车票上都记有马的匹数,从一个城市移动到另一个城市的所需时间等于城市之间道路的长度除以马的数量的结果.这位旅行家一共有n张车票,第i张车票上马的匹数是ti.一张车票只能使用一次,并且换乘所需要的时间可以忽略.求从城市a到城市b所需要的最短时间.如果无法到达城市b则输出”Impossible”. 分析:…
将车票的使用情况用二进制表示状态,对其进行转移即可. 但是我一开始写的代码是错误的(注释部分),看似思路是正确的,但是暗藏很大的问题. 枚举S,我们要求解的是dp[S][v],这个是从u转移过来的,不可以写成dp[S|(1<<i)][v].这也是一次惨痛的教训...... 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const do…
Traveling by Stagecoach dp[s][v]  从源点到达  v,状态为s,v的最小值.  for循环枚举就行了. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <string> #include <vector> #include <s…
Traveling by Stagecoach Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3407   Accepted: 1322   Special Judge Description Once upon a time, there was a traveler. He plans to travel using stagecoaches (horse wagons). His starting point an…
原题如下: Traveling by Stagecoach Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4494   Accepted: 1852   Special Judge Description Once upon a time, there was a traveler. He plans to travel using stagecoaches (horse wagons). His starting po…