[Pressure dp] HDU3182 Hamburger Magi

Source: Internet
Author: User

I have n hamburgers and m yuan (n <= 15)

Then give the energy of n hamburgers respectively.

And then the cost for n hamburgers respectively

Then there are x hamburgers in line I next n to eat before I will give the numbers of the x hamburgers

Maximum output energy

 

Analysis: n is so small, obvious pressure

The cost of each hamburger is fixed, so you only need to add an array of one-dimensional dp to record the cost of the current state.

Determine whether the order and cost are met before status transfer

1 # include <cstdio> 2 # include <cstdlib> 3 # include <cstring> 4 # include <climits> 5 # include <cctype> 6 # include <cmath> 7 # include <string> 8 # include <sstream> 9 # include <iostream> 10 # include <algorithm> 11 # include <iomanip> 12 using namespace std; 13 # include <queue> 14 # include <stack> 15 # include <vector> 16 # include <deque> 17 # include <set> 18 # include <map> 19 typedef long LL; 20 typedef long double LD; 21 # define pi acos (-1.0) 22 # define lson l, m, rt <123 # define rson m + 1, r, rt <1 | 124 typedef pair <int, int> PI; 25 typedef pair <int, PI> PP; 26 # ifdef _ WIN3227 # define LLD "% I64d" 28 # else29 # define LLD "% lld" 30 # endif31 // # pragma comment (linker, "/STACK: 1024000000,1024000000 ") 32 // LL quick (LL a, LL B) {LL ans = 1; while (B) {if (B & 1) ans * = a; a = a *; B >>= 1 ;}return ans ;}33 // inline int read () {char ch = ''; int ans = 0; while (ch <'0' | ch> '9') ch = getchar (); while (ch <= '9' & ch> = '0 ') {ans = ans * 10 + ch-'0'; ch = getchar ();} return ans;} 34 // inline void print (LL x) {printf (LLD, x); puts ("");} 35 // inline void read (double & x) {char c = getchar (); while (c <'0 ') c = getchar (); x = c-'0'; c = getchar (); while (c> = '0 ') {x = x * 10 + (c-'0'); c = getchar () ;}36 37 int a [20], B [20]; 38 int cost [1 <15], order [1 <15], dp [1 <15]; 39 int main () 40 {41 # ifndef ONLINE_JUDGE42 freopen ("in.txt", "r", stdin); 43 freopen ("out.txt", "w", stdout); 44 # endif45 int t; 46 scanf ("% d", & t); 47 while (t --) 48 {49 int n, m; 50 scanf ("% d", & n, & m); 51 for (int I = 0; I <n; I ++) 52 scanf ("% d", & a [I]); 53 for (int I = 0; I <n; I ++) 54 scanf ("% d", & B [I]); 55 memset (order, 0, sizeof (order); 56 for (int I = 0; I <n; I ++) 57 {58 int x; 59 scanf ("% d", & x ); 60 while (x --) 61 {62 int y; 63 scanf ("% d", & y); 64 order [I] | = (1 <(y-1 )); 65} 66} 67 int ans = 0; 68 memset (dp,-1, sizeof (dp); 69 memset (cost, 0, sizeof (cost )); 70 dp [0] = 0; 71 for (int I = 0; I <(1 <n); I ++) 72 for (int j = 0; j <n; j ++) 73 if (I & (1 <j) 74 cost [I] + = B [j]; 75 for (int I = 0; I <(1 <n); I ++) 76 {77 if (dp [I] =-1) 78 continue; 79 for (int j = 0; j <n; j ++) // Can I status be transferred from j status to 80 if (I & order [j]) = order [j] & cost [I] + B [j] <= m & (I & (1 <j) = 0) 81 {// Determine whether the cost of the order meets the requirements of the I parameter and whether the I parameter has been consumed by 82 dp [(1 <j) | I] = dp [I] + a [j]; 83 ans = max (ans, dp [(1 <j) | I]); 84} 85} 86 printf ("% d \ n", ans ); 87} 88 return 0; 89} 90 91 HDU 3182
HDU 3182

[Pressure dp] HDU3182 Hamburger Magi

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.