Problem I: Game King Description
Elementary school, Stubird very fond of playing the game King, one day, he found a wonderful chain combination, the chain needs 6 cards, but he has no one, but his friends have, but of course, they will not be free, but also do not rule out someone and his friendship, gave him. But they have the virtues of fulfilling others, and when they see that Stubird already have some of their favorite cards, they will give him a discount, or more, perhaps, but you can hide some of the cards and not tell them to get a lower price. Ask him how much money he needs at least to collect all the cards.
Input
The first line T, which indicates that there is a T test sample second row, n means that he has n friends (n<=100) The next line, M (0<=m<=2 6 times) indicates how many kinds of cards are set, num indicates that he has the card number is (0-5), the data to ensure that the set is not duplicated; 3 *m Line, the first row has a number, K (k<=5), indicating that the collection contains the number of cards in the next row of K number, indicating the number of each card (0-5) (will not contain NUM) The next line of a number C, indicating if you have this combination under the purchase of NUM card, the cost of C;
Output
Output minimum cost, if not possible, output-1
Sample Input161 -one of the ten to 1Sample Output6HINT
Title Link: http://4.gdutcode.sinaapp.com/problem.php?cid=1021&pid=8
This topic is really the pit father, the topic read for half an hour
Test instructions: You want to collect 6 cards, n friends, for every friend
M num//m is for you to take the card numbered num from this friend only in M case, then list m in the case
K//indicates that in this case you must have K card in hand, the following k number corresponds to the number of K cards you must have in your hand
A a .....
c//On behalf of this friend in this case take the price of the card numbered num, this 3 behavior a friend of a situation when the 3*m line ends up being the next friend's situation
Idea: Pressure DP
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <queue> #include <stack> #include <vector> #include <set> #include <map > #define L (x) (x<<1) #define R (x) (x<<1|1) #define MID (x, y) ((x+y) >>1) #define EPS 1e-8typedef long Long ll; #define FRE (i,a,b) for (i = A; I <b; i++) #define MEM (T, v) memset ((t), V, sizeof (t)) #define SF (n) SCA NF ("%d", &n) #define SFF (A, b) scanf ("%d%d", &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &A MP;C) #define PF printf#define Bug pf ("hi\n") using namespace std; #define INF 0x3f3f3f3f#define N 120int va N [7];int dp[n];int n,m;void Solve () {int i,j,cur; MEM (Dp,inf); dp[0]=0; int len=1<<6; int le,to; Fre (Cur,0,len) fre (i,0,6) {if (cur& (1<<i))) continue; if (Dp[cur]==inf) continue; le=cur^ (1<<i); for (to=0;to<len;to++) if (va[to][i]!=inf&& ((cur&to) ==to)) Dp[le]=min (Dp[le],dp[cur]+va[to][i]); }if (Dp[len-1]==inf) dp[len-1]=-1;pf ("%d\n", Dp[len-1]);} int main () {int i,j,t; SF (t); while (t--) {mem (va,inf); SF (n); int m,num,k,x,c; Fre (i,0,n) {SFF (m,num); while (m--) {int te=0; SF (k); while (k--) {SF (x); te& (1<<X))//estimated to have duplicate cards, wrong again te|= (1<<x); } SF (c); Va[te][num]=min (VA[TE][NUM],C); Estimated to have duplicate, take small}} solve (); } return 0;} /*161 0011 1011 2011 3011 4011 501*/
2015 Guangdong University of Technology ACM school race I Game King (pressure DP)