Guang Gong School race--game King

Source: Internet
Author: User

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 Input1 6 1 0 0 1 1 1 0 1 1 2 0 1 1 3 0 1 1 4 0 1 1 5 0 1Sample Output6HINT

The main idea: Uh .... No careless--the main idea is the state DP, anyway has not learned, bin God code First hanging ~ ~

/************************************************author:kuangbincreated TIME:2015/3/15 14:17:30File Name : gdut\a.cpp*************************************************/#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<time.h>using namespacestd;Const intINF =0x3f3f3f3f;intdp[ +];intst[6410],cost[6410];intnum[6410];intMain () {//freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout);    intT; scanf ("%d",&T);  while(t--){        intN; scanf ("%d",&N); intCNT =0;  for(inti =0; I < n;i++){            intm; intnn; intp; scanf ("%d%d",&m,&nn);  while(m--){                intK; scanf ("%d",&k); ST[CNT]=0; NUM[CNT]=nn;  while(k--) {scanf ("%d",&p); ST[CNT]|= (1<<p); } scanf ("%d",&cost[cnt]); CNT++; }        }         for(inti =0; I < (1<<6); i++) Dp[i] =INF; dp[0] =0;  for(inti =0; I < (1<<6); i++){            if(Dp[i] = = INF)Continue;  for(intj =0; J < cnt;j++){                if((i& (1&LT;&LT;NUM[J])! =0)Continue; if((I|st[j])! = i)Continue; Dp[i| (1&LT;&LT;NUM[J])] = min (dp[i| (1&LT;&LT;NUM[J])],dp[i]+Cost[j]); }        }        intTot = (1<<6)-1; if(Dp[tot] = = INF) Dp[tot] =-1; printf ("%d\n", Dp[tot]); }    return 0;}
View Code

Guang Gong School race--game King

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.