COdeforces # mongod Cunning Gena (pressure DP)

Source: Internet
Author: User
Tags bitset

COdeforces # mongod Cunning Gena (pressure 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 hisNFriends that they will solve the problems for him.

The maid are offeredMProblems on the contest. For each friend, Gena knows what problems he can solve. But Gena's friends won't agree to help Gena for nothing:I-Th friend asks GenaXIRubles for his help in solving all the problems he can. Also, the friend agreed to write a code for Gena only if Gena's computer is connected to at leastKIMonitors, each monitor costsBRubles.

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 integersN,MAndB(1? ≤?N? ≤? 100; 1? ≤?M? ≤? 20; 1? ≤?B? ≤? 109)-the number of Gena's friends, the number of problems and the cost of a single monitor.

The following 2NLines describe the friends. Lines number 2IAnd (2I? +? 1) contain the information aboutI-Th friend. The 2I-Th line contains three integersXI,KIAndMI(1? ≤?XI? ≤? 109; 1? ≤?KI? ≤? 109; 1? ≤?MI? ≤?M)-The desired amount of money, monitors and the number of problems the friend can solve. The (2I? +? 1)-th line containsMIDistinct positive integers-the numbers of problems thatI-Th friend can solve. The problems are numbered from 1M.

Output

Print the minimum amount of money Gena needs to spend to solve all the problems. Or print-1, if this cannot be achieved.

Sample test (s) input
2 2 1100 1 12100 2 11
Output
202
Input
3 2 5100 1 11100 1 12200 1 21 2
Output
205
Input
1 2 11 1 11
Output
-1
We found that because the number of required monitors is different, we need to sort the number of monitors from small to large, and then press DP, because the number of the following monitors exceeds the front, therefore, we do not have to consider whether the monitor is adequate. The following is the pressure DP.
#include
 
  #include
  
   #include#include
   
    #include
    
     #include
     
      #include
      
       #include
       
        #include
        #include
         
          #includewww.bkjia.com
          
           using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )typedef long long LL;typedef pair
           
            pil;const LL INF=1e19;LL dp[1<<20];struct node{ int cost,k; int s;}e[110];int n,m,b,num;int cmp(node l1,node l2){ return l1.k
            
           
          
         
       
      
     
    
   
  
 

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.