博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2686 Traveling by Stagecoach 状态压缩
阅读量:4114 次
发布时间:2019-05-25

本文共 1275 字,大约阅读时间需要 4 分钟。

题意:有m个城市,其中有些城市之间 有道路连通,且有一定的距离w,现在你有n张卡,每张卡有个权值t能让经过
通过
道路的费用变为w/t,求从城市a到城市b的 最小的花费。
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; #define MM(a) memset(a,0,sizeof(a)) typedef long long ll; typedef unsigned long long ULL; const int mod = 1000000007; const double eps = 1e-10; const int inf = 0x3f3f3f3f; const int big=50000; int max(int a,int b) {return a>b?a:b;}; double min_(double a,double b) {return a
G[35]; double dp[1<<10][35]; void solve() { double ans=inf; for(int s=0;s<=(1<
=0;s--) { ans=min_(ans,dp[s][b]); for(int u=1;u<=m;u++)//枚举起点u for(int j=1;j<=n;j++)//使用第j张票 if(s&(1<<(j-1))) for(int i=0;i
=inf-1) printf("Impossible\n"); else printf("%.3f\n",ans); } int main() { while(~scanf("%d %d %d %d %d",&n,&m,&p,&a,&b)) { if(!n&&!m&&!p&&!a&&!b) break; for(int i=1;i<=n;i++) scanf("%d",&t[i]); for(int i=1;i<=m;i++) G[i].clear(); int f,t;double c; for(int i=1;i<=p;i++) { scanf("%d %d %lf",&f,&t,&c); G[f].push_back((e){t,c}); G[t].push_back((e){f,c}); } solve(); } return 0; }
分析:状态压缩dp[s][u]表示在当前剩余票的情况为s(状压),所处城市为u的情况下所需要的最小的花费
不过还需要注意 本解法的枚举顺序,是先枚举当前票的状态...然后再是起点,使用的票,终点。

转载地址:http://dtgsi.baihongyu.com/

你可能感兴趣的文章
C# 学习笔记(四) 结构体实现接口后是值类型还是引用类型
查看>>
C# 装箱和拆箱
查看>>
C# 学习笔记(五) ++/--运算符重载的意义
查看>>
C# virtual和abstract的区别
查看>>
C++ VS2010中 C++创建DLL图解
查看>>
c# ==与equals有什么区别
查看>>
Sql Server中架构的理解
查看>>
ASCII码表
查看>>
C# 浅析值类型与引用类型的内存分配
查看>>
浮点型变量在计算机内存中的存储格式
查看>>
CPU字节序
查看>>
C# 结构体访问器错误提示
查看>>
C# BackgroundWorker的使用
查看>>
P2P 穿透内网,连接动态ip,内网ip打洞,p2p实现原理
查看>>
C# 设置线程的默认CultureInfo
查看>>
计算机视觉与图像处理、模式识别、机器学习学科之间的关系
查看>>
C# 隐式接口与显式接口实现
查看>>
MD5与字符串编码
查看>>
C# 函数式编程
查看>>
C# Dispose, Finalization, and Resource Management
查看>>