hunnu 11101 fix 状态压缩的DP
2012-04-16 00:03
134 查看
the problem requires that to calculate a minimum length of verge which is needed in order to fix all the point unfixed to the plain with fixed points.
状态压缩的dp,每个状态,枚举每一个可以添加活点的位置,每次的未固定的点,枚举可以连接的以固定的点
状态压缩的dp,每个状态,枚举每一个可以添加活点的位置,每次的未固定的点,枚举可以连接的以固定的点
#include<stdio.h> #include<math.h> #define N 18 #define INF 1e100 int moveL[N+1]; void cal_move() { int i; } double min(double a,double b) { return a<b?a:b; } struct node { int x,y; void input(){ scanf("%d%d",&x,&y); } }point ; double dist ; double dp[1<<N]; int main() { // cal_move(); int n,i,j,k,c,ini; for(i=0;i<=N;++i) moveL[i]=1<<i; while(scanf("%d",&n)==1&&n) { ini = 0; for(i = 0;i<n;++i) { point[i].input(); scanf("%d",&c); if(c) ini|=moveL[i]; } for(i=0;i<n;++i) for(j=0;j<=i;++j) dist[i][j]=dist[j][i]= sqrt((point[i].x-point[j].x+0.0)*(point[i].x-point[j].x+0.0)+(point[i].y-point[j].y+0.0)*(point[i].y-point[j].y+0.0)); for(i=0;i<moveL ;++i) dp[i]=INF; dp[ini]=0.0; double mina,minb; for(i=ini;i<moveL ;++i) /**if dp[i]==INF it's not necessary to update its next staus however on the hdu_3362 ,because of longer time,it can be AC without this judgement, hunnu not */ if(dp[i]<INF) for(j=0;j<n;++j) if((i>>j&1)==0) { mina=minb=INF; for(k=0;k<n;++k) { if(i>>k&1) { if(dist[j][k]<mina) { minb=mina; mina=dist[j][k]; } else if(dist[j][k]<minb) minb=dist[j][k]; } } if(dp[i|moveL[j]]>dp[i]+mina+minb) dp[i|moveL[j]]=dp[i]+mina+minb; } if(dp[moveL -1]==INF) printf("No Solution\n"); else printf("%.6lf\n",dp[moveL -1]); } return 0; }
相关文章推荐
- HDU 3362 Fix (状态压缩DP)
- UVA 10651 Pebble Solitaire 状态压缩dp
- 状态压缩中常用的位运算(DP)
- hdu 1565 方格取数(1)(DP 状态压缩)
- HDU_4317 Unfair Nim 状态压缩dp
- UVA 6625(状态压缩dp)
- COJ 1129 送货到家 (状态压缩DP)
- POJ 2441 Arrange the Bulls 状态压缩DP
- 洛谷 1052 dp 状态压缩
- 状态压缩·一(状态压缩DP)
- Twenty Questions UVA - 1252 (状态压缩dp)
- poj2288 Islands and Bridges 状态压缩dp
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
- HDU 4539 排兵布阵 【状态压缩dp】
- (复习)(转)03进制状态压缩DP——HDU3001 Travelling 旅行商问题
- HDU - 2825(AC自动机+状态压缩DP(需要优化))
- HDU3311Dig The Wells(斯坦纳树,spfa+状态压缩DP)可作模板
- 【例题】【图论&DP(状压)】NKOJ 1905 慢跑小路 【S2状态压缩】
- poj2411Mondriaan's Dream(状态压缩dp)
- hdu4739(状态压缩dp+正方形判断)