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 is too complex, so he made a arrangement with him n friends that they would solve the problems f or him.
The participants is offered m problems on the contest. For each friend, the Gena knows what problems he can solve. But Gena's friends won ' t agree to help Gena for nothing:the i-th friend asks Gena XI rubles for he help in solving all t He problems he can. Also, the friend agreed to write a code for Gena only if Gena ' s computer are connected to at least Ki monitors, each Monito R costs B rubles.
Gena is careful with money, so he wants to spend as little money as possible to solve all the problems. Help Gena, tell him how to spend the smallest possible amount of money. Initially, there ' s no monitors connected to Gena ' s computer.
Input
The first line contains three integers n, m and B (1?≤?n?≤?100; 1?≤?m?≤?20; 1?≤?b?≤?109)-the number of Gena ' s friends, t He number of problems and the cost of a single monitor.
The following 2n lines describe the friends. Lines number 2i and (2i?+?1) contain the information about the i-th friend. The 2i-th line contains three integers xi, ki and mi (1?≤?xi?≤?109; 1?≤?ki?≤?109; 1?≤?mi?≤?m)-the desired amount of mone Y, monitors and the number of problems the friend can solve. The (2i?+?1)-th line contains MI distinct positive integers-the numbers of problems that the i-th friend can solve. The problems is numbered from 1 to M.
Output
Print the minimum amount of money Gena needs to spend to solve all the problems. Or Print-1, if this cannot is achieved.
Sample Test (s)
Input
2 2 1
100 1 1
2
100 2 1
1
Output
202
Input
3 2 5
100 1 1
1
100 1 1
2
200 1 2
1 2
Output
205
Input
1 2 1
1 1 1
1
Output
-1
When I see m so small, I think directly of the pressure DP, but there is a monitors limit, can not be violent enumeration of this value
The input data can be first sorted by each person's monitors, so from small to large enumeration of everyone, side recursive side record the answer can
/************************************************************************* > File Name:CF417D.cpp > Autho R:alex > Mail: [email protected] > Created time:2015 March 16 Monday 12:33 11 seconds ********************************* ***************************************/#include <map>#include <set>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace STD;Const DoublePI =ACOs(-1.0);Const Long LongINF = (1LL << -);Const DoubleEPS =1e-15;typedef Long LongLL;typedefPair <int,int> PLL; LL dp[(1<< -) +Ten];structnode{intStaintCostintNum;} fri[ the];intCMP (Node A, Node B) {returnA.num < B.num;}intMain () {intN, M, b; while(~scanf("%d%d%d", &n, &m, &b)) { for(inti =0; I <= (1<< m); ++i) {Dp[i] = inf; } dp[0] =0; for(inti =1; I <= N; ++i) {intCnt Fri[i].sta =0;intXscanf("%d%d%d", &fri[i].cost, &fri[i].num, &cnt); for(intj =0; J < CNT; ++J) {scanf("%d", &x); Fri[i].sta |= (1<< (X-1)); }} LL ans= inf; Sort (Fri +1, Fri +1+ N, CMP); for(inti =1; I <= N; ++i) { for(intj =0; J < (1<< m); ++J) {dp[j | fri[i].sta] = MIN (dp[j] + fri[i].cost, DP[J | fri[i].sta]); } ans = min (ans, dp[(1<< m)-1] + (LL) fri[i].num * b); }if(Ans >= inf) {printf(" -1\n"); }Else{cout<< ans << Endl; } }return 0;}
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
cf417d---cunning Gena (sequence + image indent DP)