点集配对问题(状压dp)
来源:互联网 发布:什么是可逆矩阵 编辑:程序博客网 时间:2024/05/08 10:41
d[s]为集合s配对后的最小距离和,dp[s]=min(dp[s],dp[s-{i}-{j}]+|pipj|)。
//// main.cpp// Richard//// Created by 邵金杰 on 16/10/1.// Mail:1016427040@qq.com or jasonshaosjj@gmail.com// Copyright © 2016年 邵金杰. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int maxn=20;const int inf=1000000000;double dist(double x,double y,double z){ return sqrt(x*x+y*y+z*z);}int x[maxn],y[maxn],z[maxn];double dp[(1<<maxn)];int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d%d",&x[i],&y[i],&z[i]); for(int i=1;i<(1<<n);i++) dp[i]=inf; dp[0]=0; for(int s=3;s<(1<<20);s++) { int p=0; while(!(s&(1<<p))) p++; for(int j=p+1;j<20;j++) { if(s&(1<<j)) { dp[s]=min(dp[s],dp[s-(1<<p)-(1<<j)]+dist(x[p]-x[j],y[p]-y[j],z[p]-z[j])); } } } printf("%.3f\n",dp[(1<<n)-1]); return 0;}
0 0
- 点集配对问题 状压DP
- 点集配对问题(状压dp)
- 点集配对问题 集合DP 按位DP
- 点集配对问题
- Most Powerful (zoj 3471 状压dp 点集配对)
- 点集配对 【dp 位运算】
- 状态压缩dp 最优配对问题
- Uva 10911 Forming Quiz Teams(状压dp 最优配对问题)
- 最优配对问题(集合上的动态规划) —— 状压DP
- 集合DP 点集匹配问题
- UVA 10911 Forming Quiz Teams(dp + 集合最优配对问题)
- 【bzoj1237】【scoi2008】【配对】【dp】
- [BZOJ1786&&BZOJ1831]配对 dp
- BZOJ1237 配对 [DP]
- bzoj1237 wikioi2430 [SCOI2008]配对 dp
- 【bzoj 1237】[SCOI2008]配对 dp
- [BZOJ1237][SCOI2008]配对(dp)
- poj 1141 DP 括号配对
- JAVA基础之InputStream转换成String
- Spark Mllib 回归学习笔记一(java):线性回归(线性,lasso,岭),广义回归
- hdu 4858 图的模拟+vector 简单题
- 求职之C++小知识点整理
- 安卓开发ListView的运用
- 点集配对问题(状压dp)
- 51nod 1050 循环数组最大子段和
- 装饰设计模式
- javascript闭包传参和事件的循环绑定示例探讨
- C语言--小学生计算机辅助教学系统
- 【codeforces 721B】B. Passwords【输入密码按长度非递减顺序输入,每输一次耗时1秒,输错k次等待5秒,最后一行为正确密码,问消耗的最少和最多时间】
- 微机原理--第二章(9)描述符和页表项
- Unity3D自学笔记——GUI组件的应用
- uva困难的串