状压DP

dp[s][p]用了哪几张票,到哪个节点的最小费用。

注意:G++ %.3lf输出会WA,但C++能过;改成%.3f,C++,G++都能AC

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<algorithm>
using namespace std; const double INF = ;
int n, m, p, a, b;
int t[];
struct Edge
{
int to;
int dis;
}e[];
int tot;
vector<int>g[];
double dp[][]; int main()
{
while (~scanf("%d%d%d%d%d", &n, &m, &p, &a, &b))
{
if (n == && m == && p == && a == && b == ) break; tot = ;
for (int i = ; i <= m; i++) g[i].clear();
for (int i = ; i < ( << n); i++)
for (int j = ; j <= m; j++) dp[i][j] = INF; for (int i = ; i < n; i++) scanf("%d", &t[i]);
for (int i = ; i <= p; i++)
{
int u, v, c; scanf("%d%d%d", &u, &v, &c);
e[++tot].to = v; e[tot].dis = c; g[u].push_back(tot);
e[++tot].to = u; e[tot].dis = c; g[v].push_back(tot);
} dp[][a] = ;
for (int i = ; i < ( << n); i++)
{
for (int j = ; j <= m; j++)
{
if (dp[i][j] == INF) continue;
for (int k = ; k < n; k++)
{
if ((i | ( << k)) == i) continue;
for (int s = ; s < g[j].size(); s++)
{
dp[(i | ( << k))][e[g[j][s]].to] = min(
dp[(i | ( << k))][e[g[j][s]].to],
dp[i][j] + 1.0*e[g[j][s]].dis / (1.0*t[k]));
}
}
}
} double ans = INF;
for (int i = ; i < ( << n); i++)
ans = min(ans, dp[i][b]);
if (ans == INF) printf("Impossible\n");
else printf("%.3f\n", ans);
}
return ;
}

POJ 2686 Traveling by Stagecoach的更多相关文章

  1. POJ 2686 Traveling by Stagecoach(状压二维SPFA)

    Traveling by Stagecoach Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3407   Accepted ...

  2. poj 2686 Traveling by Stagecoach ---状态压缩DP

    题意:给出一个简单带权无向图和起止点,以及若干张马车车票,每张车票可以雇到相应数量的马. 点 u, v 间有边时,从 u 到 v 或从 v 到 u 必须用且仅用一张车票,花费的时间为 w(u, v) ...

  3. POJ 2686 Traveling by Stagecoach(状压DP)

    [题目链接] http://poj.org/problem?id=2686 [题目大意] 给出一张无向图,你有n张马车票每张车票可以租用ti匹马, 用一张马车票从一个城市到另一个城市所用的时间为这两个 ...

  4. POJ 2686 Traveling by Stagecoach 壮压DP

    大意是有一个人从某个城市要到另一个城市(点数<=30) 然后有n个马车票,相邻的两个城市走的话要消耗掉一个马车票. 花费的时间呢,是马车票上有个速率值,用边/速率就是花的时间. 问最后这个人花费 ...

  5. POJ 2686 Traveling by Stagecoach (状压DP)

    题意:有一个人从某个城市要到另一个城市, 有n个马车票,相邻的两个城市走的话要消耗掉一个马车票.花费的时间呢,是马车票上有个速率值 ,问最后这个人花费的最短时间是多少. 析:和TSP问题差不多,dp[ ...

  6. poj2686 Traveling by Stagecoach

                    http://poj.org/problem?id=2686                                                  Trav ...

  7. Traveling by Stagecoach(POJ 2686)

    原题如下: Traveling by Stagecoach Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4494   Ac ...

  8. Traveling by Stagecoach 状态压缩裸题

    Traveling by Stagecoach dp[s][v]  从源点到达  v,状态为s,v的最小值.  for循环枚举就行了. #include <iostream> #inclu ...

  9. POJ2686 Traveling by Stagecoach(状压DP+SPFA)

    题目大概是给一张有向图,有n张票,每张票只能使用一次,使用一张票就能用pi匹马拉着走过图上的一条边,走过去花的时间是边权/pi,问从a点走到b点的最少时间是多少. 用dp[u][S]表示当前在u点且用 ...

随机推荐

  1. ubuntu setup adb tool

    sudo add-apt-repository ppa:nilarimogard/webupd8sudo apt-get updatesudo apt-get install android-tool ...

  2. .bash_profile和.bashrc的什么区别

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置./etc/bashrc:为每一个运 ...

  3. liunx 平台下软件包管理

    RPM/DPKG 两大阵营简介 在 GNU/Linux( 以下简称 Linux) 操作系统中,RPM 和 DPKG 为最常见的两类软件包管理工具,他们分别应用于基于 RPM 软件包的 Linux 发行 ...

  4. 【Android 应用开发】Android 开发 之 JNI入门 - NDK从入门到精通

    NDK项目源码地址 : -- 第一个JNI示例程序下载 : GitHub - https://github.com/han1202012/NDKHelloworld.git -- Java传递参数给C ...

  5. javascript语句语义大全(4)

    1. var arr1=new Array(2) var arr2=new Array() var arr3=new Array("a","b") var ar ...

  6. const与static的区别

    const就是只读的意思,只在声明中使用;const修饰的数据类型是指常类型,常类型的变量或对象的值是不能被更新的. const的作用: (1)可以定义const常量,具有不可变性. (2)便于进行类 ...

  7. IDL 实现 EOF(经验正交函数分析)

    关于EOF详细介绍请wiki http://en.wikipedia.org/wiki/Empirical_orthogonal_functions或者Google之. 与PCA一样,EOF也是遥感多 ...

  8. [转]Linux下CodeBlocks的交叉编译

    原文链接:http://blog.sina.com.cn/s/blog_602f87700100kujh.html Sam一直是Makefile流,这些天需要移植一些游戏引擎模块.这些模块在其它嵌入式 ...

  9. 使用PHP Socket 编程模拟Http post和get请求

    这里给大家分享一段使用PHP Socket 编程模拟Http post和get请求的代码,非常的实用,结尾部分我们再讨论下php模拟http请求的几种方法. <?php /** * 使用PHP ...

  10. hdu_5691_Sitting in Line(状压DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5691 题意:中文,不解释 题解:设dp[i][j]表示当前状态为i,以第j个数为末尾的最忧解,然后dp ...