状态压缩dp 最优配对问题
来源:互联网 发布:种草 网络语言 英文 编辑:程序博客网 时间:2024/04/27 18:02
在空间中的n(n为偶数)个点,配成n对,然后使得每一个点在一个点对中。所有的点对的距离之和最小
#include <cstdio>#include <iostream>#include <algorithm>#include <queue>#include <stack>#include <climits>#include <cstring>#include <cmath>#include <map>#include <set>#define INF 100000000using namespace std;int n;int x[1000];int y[1000];int d[1<< 21];int dist(int a,int b){return (x[a] - x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a] - y[b]);}int main(){while(cin >> n){for(int i = 0;i < n;i++){cin >> x[i] >> y[i];}memset(d,0,sizeof(d));for(int i = 0;i < (1<<n);i++){d[i] = INF;}d[0] = 0;//依次枚举不同的集合for(int s = 0;s < (1<<n);s++){ int i,j;//d[s] = min(|PiPj| + d[s-{i}-{j}]); for(i = 0;i < n;i++){ //枚举其中一个点 if(s & (1 << i)) break; } for(j = i+1;j < n;j++){ //再找另外一个点 if(s & (1 << j)){ //比较去掉这两个点的集合最小值的方法 d[s] = min(d[s],dist(i,j)+d[s^(1<<i)^(1<<j)]); } }}printf("%d\n",d[(1 << n)-1]);} return 0;}
觉得的状态压缩dp适合于n较小但是状态异常复杂的dp环境
0 0
- 状态压缩dp 最优配对问题
- UVA 10911 Forming Quiz Teams(dp + 集合最优配对问题)
- 最优配对问题
- 最优配对问题
- 最优配对问题
- 最优配对问题
- jzoj 3420 最优配对问题
- Uva 10911 Forming Quiz Teams(状压dp 最优配对问题)
- 最优配对问题(集合上的动态规划) —— 状压DP
- SGU132 状态压缩~最优值
- uva11008 状态压缩~最优值
- hdu1565 状态压缩~最优值
- hdu4049 状态压缩~最优值
- hdu4284 状态压缩~最优值
- hdu3920 状态压缩~最优值
- hdu2167 状态压缩~最优值
- hdu3681 状态压缩最优值
- poj1691 状态压缩~最优值
- debian旧光盘下载地址
- Android性能优化典范(一)
- PHP裁剪图片插件记录
- Caffe+Ubuntu 14.04 + Cuda6.5 新手安装记录
- 获取以太网子网掩码
- 状态压缩dp 最优配对问题
- 关于vc6.0各种新建工程的含义
- Gradle 1.12用户指南翻译——第二十四章. Groovy 插件
- Android ramdisk.img system.img userdata.img介绍与使用
- 服务器监控工具zabbix、nagios、ganglia
- Java图片处理开源框架
- Lisp的前世今生
- hdu2035 人见人爱A^B(快速幂取模)
- Sort an array alphabetically in Ruby but with capitalised words at the end