HDUOJ Clear All of Them I 状压DP

Clear All of Them I

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 122768/62768 K (Java/Others)
Total Submission(s): 1455    Accepted Submission(s): 484

Problem Description

Acmers have been the Earth Protector against the evil enemy for a long time, now it’s your turn to protect our home.
  There are 2 * n enemies in the map. Your task is to clear all of them with your super laser gun at the fixed position (x, y).
  For
each laser shot, your laser beam can reflect 1 times (must be 1 times),
which means it can kill 2 enemies at one time. And the energy this shot
costs is the total length of the laser path.
  For example, if you
are at (0, 0), and use one laser shot kills the 2 enemies in the order
of (3, 4), (6, 0), then the energy this shot costs is 5.0 + 5.0 = 10.
00.
  Since there are 2 * n enemies, you have to shot n times to
clear all of them. For each shot, it is you that select two existed
enemies and decide the reflect order.
  Now, telling you your
position and the 2n enemies’ position, to save the energy, can you tell
me how much energy you need at least to clear all of them?
  Note that:
   > Each enemy can only be attacked once.
   > All the positions will be unique.
   > You must attack 2 different enemies in one shot.
   > You can’t change your position.

Input

The first line contains a single positive integer T( T <= 100 ), indicates the number of test cases.
For each case:
  There are 2 integers x and y in the first line, which means your position.
  The second line is an integer n(1 <= n <= 10), denote there are 2n enemies.
  Then there following 2n lines, each line have 2 integers denote the position of an enemy.
  
  All the position integers are between -1000 and 1000.

Output

For
each test case: output the case number as shown and then print a
decimal v, which is the energy you need at least to clear all of them
(round to 2 decimal places).

Sample Input

2

0 0
1
6 0
3 0

0 0
2
1 0
2 1
-1 0
-2 0

Sample Output

Case #1: 6.00
Case #2: 4.41

Source

2011 Multi-University Training Contest 9 - Host by BJTU

网上给这道题的定义为状压DP优化,但我实在看不出哪儿有优化的意义,然后,我就TLE了。

HDUOJ Clear All of Them I 状压DP

时间: 2025-02-01 15:55:36

HDUOJ Clear All of Them I 状压DP的相关文章

HDU 3920 Clear All of Them I 状压DP

Clear All of Them I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 122768/62768 K (Java/Others) Total Submission(s): 1681    Accepted Submission(s): 544 Problem Description Acmers have been the Earth Protector against the evil enemy for a lo

BZOJ 1087: [SCOI2005]互不侵犯King( 状压dp )

简单的状压dp... dp( x , h , s ) 表示当前第 x 行 , 用了 h 个 king , 当前行的状态为 s . 考虑转移 : dp( x , h , s ) = ∑ dp( x - 1 , h - cnt_1( s ) , s' ) ( s and s' 两行不冲突 , cnt_1( s ) 表示 s 状态用了多少个 king ) 我有各种预处理所以 code 的方程和这有点不一样 ------------------------------------------------

COdeforces#417D Cunning Gena(状压DP)

A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his n friends that they will solve the problems for him. The participants

POJ 3254 Corn Fields (状压DP,轮廓线DP)

题意: 有一个n*m的矩阵(0<n,m<=12),有部分的格子可种草,有部分不可种,问有多少种不同的种草方案(完全不种也可以算1种,对答案取模后输出)? 思路: 明显的状压DP啦,只是怎样压缩状态?跟轮廓线DP一样,按格子为单位来设计状态,一个状态只需要表示到其上方和左方的格子,所以最多只需要保存min(n,m)个01状态就行了(可以尝试旋转一下矩阵),最多需要12位.用哈希表来做会比较快吧,不用去考虑无效的状态,比如出现相邻两个1. 1 //#include <bits/stdc++.

BZOJ 3446: [Usaco2014 Feb]Cow Decathlon( 状压dp )

水状压dp. dp(x, s) = max{ dp( x - 1, s - {h} ) } + 奖励(假如拿到的) (h∈s). 时间复杂度O(n * 2^n) ---------------------------------------------------------------------------------- #include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < n; ++i) #define clr(x

Codeforces Gym 100676G Training Camp 状压dp

http://codeforces.com/gym/100676 题目大意是告诉你要修n门课,每门课有一个权值w[i], 在第k天修该课程讲获得k*w[i]的学习点数,给出了课程与先修课程的关系,要修该课程必须修完先修课程.问最多能学到多少点数. 非常简单的一道状压dp(一开始我还误导队友写成两维的去了 T^T); dp[s] : s 的二进制存放的是已经选择的课程,在该状态下的能获得的最大的点数. 这时如果再学一门课程k,将转移到状态ss (s | (1 << k) ) ,能否转移需要判断合

HDU 4924 Football Manager(状压DP)

题目连接 : http://acm.hdu.edu.cn/showproblem.php?pid=4924 题意 : n(<=20)个人选出11个人作为首发组成a-b-c阵容,每个人都有自己擅长的位置,并且每个人和其他人会有单向的厌恶和喜欢关系,每个人对于自己擅长的位置都有两个值CA和PA,有喜欢或者厌恶关系的两个人在一起也会影响整个首发的CA总值,要求选出一套阵容使得CA最大,或者CA一样的情况下PA最大. 思路 : 状压搞,dp[s]s的二进制表示20个人中选了那几个人,然后规定选进来的顺序

ZOJ 3471 Most Powerful(状压DP)

Description Recently, researchers on Mars have discovered N powerful atoms. All of them are different. These atoms have some properties. When two of these atoms collide, one of them disappears and a lot of power is produced. Researchers know the way

Spoj 9894 Tichu 状压dp

题目链接:点击打开链接 题意: 给定13张各不相同的扑克牌,问最少需要几手打出 每手打出的牌必须符合以下任意标准之一: 1.任意单张 2.相同数字2张 3.相同数字3张 4.相同数字4张 5.相同数字3张+相同数字2张 6.连续5个及5个以上的数字 思路: 状压dp,dp[i]表示选了i的状态的最小牌数 然后要预处理出能一次打出的状态,这样不会t.. #include <iostream> #include <algorithm> #include <cstring>