HDU 3182 Hamburger Magi (pressure dp)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 3182


Problem DescriptionIn the mysterious forest, there is a group of Magi. most of them like to eat human beings, so they are called "The Ogre Magi", but there is an special one whose favorite food is hamburger, having 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 will cost him Ei energy, (He can use in total M energy each day ). in addition, some hamburgers can't be made directly, for example, HamMagi can make a "Big Mac" only if "New Orleams roasted burger combo" and "Mexican twister combo" are all already made. of course, he will only make each kind of hamburger once within a single day. now he wants to know the maximal total value he can get after the whole day's hard work, but he is too tired so this is your 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 two integers N, E (1 <= N <= 15, 0 <= E <= 100 ), indicating there are N kinds of hamburgers can be made and the initial energy he has.
The second line of each case contains N integers V1, V2... VN, (Vi <= 1000) indicating the value of each kind of hamburger.
The third line of each case contains N integers E1, E2... EN, (Ei <= 100) indicating the energy each kind of hamburger cost.
Then N lines follow, each line starts with an integer Qi, then Qi integers follow, indicating the hamburgers that making ith hamburger needs.
OutputFor each line, output an integer indicating the maximum total value HamMagi can get.
Sample Input
14 90243 464 307 298 79 58 0 723 2 3 42 1 41 10
 
Sample Output
298
 
SourceHDU 2009-10 Programming Contest

// Question:
// Make a hamburger by yourself. Each hamburger has its own cost and value,

Some hamburgers must be prepared only after some other hamburgers have been prepared,

Give the initial amount of money for this person and ask what is the maximum value.

The code is as follows:

# Include <cstdio> # include <cstring> # include <algorithm> using namespace std; const int maxn = 17; int a [maxn] [maxn]; // the ordered int dp [1 <maxn]; // dp [I] indicates the maximum value of I state, int no_cost [1 <maxn]; // money [I] indicates the amount of money remaining in the I state int cost [maxn], get_v [maxn]; int n, money; int judge (int m, int state) {// check whether the question is given when a hamburger is made. All the hamburgers to be made before it is made have been made for (int I = 1; I <= a [m] [0]; I ++) {if (! (State & (1 <(a [m] [I]-1) {return 0 ;}} return 1 ;}int main () {int t; scanf ("% d", & t); while (t --) {scanf ("% d", & n, & money); for (int I = 1; I <= n; I ++) {scanf ("% d", & get_v [I]) ;}for (int I = 1; I <= n; I ++) {scanf ("% d", & cost [I]) ;}int tt; for (int I = 1; I <= n; I ++) {scanf ("% d", & a [I] [0]); for (int j = 1; j <= a [I] [0]; j ++) {scanf ("% d", & a [I] [j]) ;}}for (int I = 0; I <= (1 <n)-1; I ++) {dp [I] =-1111; no_cost [I] = 0;} dp [0] = 0; no_cost [0] = money; int ansm = 0; for (int I = 0; I <= (1 <n)-1; I ++) {for (int j = 1; j <= n; j ++) {if (I & 1 <(j-1) // if the I-th hamburger has been done, it will not be updated {continue ;} int now = I | (1 <(j-1 )); // Make the I-th hamburger if (dp [now] <dp [I] + get_v [j] & judge (j, I) & amp; no_cost [I]> = cost [j]) {dp [now] = dp [I] + get_v [j]; no_cost [now] = no_cost [I]-cost [j]; ansm = max (ansm, dp [now]) ;}} printf ("% d \ n ", ansm);} return 0 ;}


HDU 3182 Hamburger Magi (pressure dp)

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.