Hamburger Magi (Hdu 3182)

Source: Internet
Author: User

Hamburger Magi

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 437 Accepted Submission (s): 144


Problem DescriptionIn The mysterious forest, there is a group of Magi. Most of them-eat human beings, so they was called "the Ogre Magi", but there was an special one whose favorite food Is hamburger, has been jeered by the others as "the Hamburger Magi".
Let's give the Hamburger Magi a nickname "Hammagi", Hammagi don ' t only love to eat but also to make hamburgers, he makes N Hamburgers, and he gives these each hamburger a value as Vi, and each would cost him Ei energy, (he can use the total M ene Rgy each day). In addition, some hamburgers can ' t being made directly, for example, Hammagi can make a "Big Mac" only if "New orleams roaste D Burger Combo "and" Mexican Twister combo "is all already made. Of course, he would only make each kind of hamburger once within a. Now he wants to know the maximal total value he can get through the whole day's hard work, but he's too tired so this is yo ur task now!

Inputthe first line consists of an integer C (c<=50), indicating the number of test cases.
The first line of each case consists of integers n,e (1<=n<=15,0<=e<=100), indicating there is N kinds of Hamburgers can made and the initial energy he had.
The second line of all case contains N integers v1,v2 ... VN, (vi<=1000) indicating the value of each kind of hamburger.
The third line of all case contains N integers e1,e2 ... EN, (ei<=100) indicating the kind of hamburger cost.
Then N lines-follow, each line starts with a integer qi, then Qi integers follow, indicating the hamburgers that making I Th hamburger needs.

Outputfor each line, output a integer indicating the maximum total value Hammagi can get.

Sample Input14 90243 464 307 298 0 723 2 3 1 10Sample Output298 test instructions: Just give you n pieces of bread, give him the value and the energy you need. Give the character physical strength, and then each bread do need certain conditions, that is, before the bread to do a few other bread to do well. Ask the last to get the most value. Idea: pressure DP; Total pow (2,n) state. Dp[i] represents the maximum value obtained in the state I.
1#include <stdio.h>2#include <algorithm>3#include <iostream>4#include <string.h>5#include <stdlib.h>6#include <queue>7#include <stack>8 using namespacestd;9typedefstructQQTen { One     intX//maximum value in current state A     intY//keep track of the rest of your energy - } mm; -typedefstructpp the { -     intx; -     inty; -     intCNT; +     inta[ -]; -} SS;//value consumption and requirements of the bread +SS kk[ A]; AMM dp[1<< -]; at intMainvoid) - { -     intn,i,j,k,p,q; -scanf"%d",&k); -      while(k--) -     { inscanf"%d%d",&p,&q); -          for(i=0; i<p; i++) to         { +scanf"%d",&kk[i].x); -         } the          for(i=0; i<p; i++) *         { $scanf"%d",&kk[i].y);Panax Notoginseng         } -          for(i=0; i<p; i++) the         { +scanf"%d",&kk[i].cnt); A              for(j=0; j<kk[i].cnt; J + +) the             { +scanf"%d",&kk[i].a[j]); -kk[i].a[j]-=1; $             } $         } -          for(i=0; i< (1<< -); i++) -         { thedp[i].x=0; -dp[i].y=- -;Wuyi         } the         intmaxx=0; -dp[0].y=q;//Initialize Wu          for(i=1; i< (1&LT;&LT;P); i++) -         { About              for(j=0; j<p; J + +) $             { -                 if(i& (1&LT;&LT;J))//determine if it is in the current state -                 { -                     intc=i^ (1&LT;&LT;J);//find the previous state of this state A                     ints=0; +                      for(s=0; s<kk[j].cnt; s++)//determine whether the requirement is set up in the previous state if there is a requirement to make this bread the                     { -                         if((c& (1<< (Kk[j].a[s])) = =0) $                         { the                              Break; the                         } the                     } the                     if(s==kk[j].cnt) -                     { in                         if(dp[c].y>=kk[j].y) the                         { the                             intcc=dp[c].x+kk[j].x; About                             if(cc>dp[i].x) the                             { thedp[i].x=cc; thedp[i].y=dp[c].y-kk[j].y; +                             } -                             if(dp[i].x>Maxx) the                             {Bayimaxx=dp[i].x;//Update Maximum Value the                             } the                         } -                     } -                 } the  the             } the  the         } -printf"%d\n", Maxx); the     } the     return 0; the}
pressure DP

Hamburger Magi (Hdu 3182)

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.