Inviting friends (hdu3244 & zoj3187) full backpack + binary

Source: Internet
Author: User
Inviting friends Time Limit: 1 second memory limit: 32768 KB

You want to hold a birthday party, inviting as your friends as possible, but you have to prepare enough food for them. for each person, you need n kinds of ingredient to make good food. you can use the ingredients in your kitchen, or buy some new ingredient packages. there are exactly two kinds of packages for each kind of ingredient: small and large.

We use 6 Integers to describe each ingredient :,X, Y, S1, P1, S2, p2, WhereXIs the amount (of this ingredient) needed for one person,YIs the amount currently available in the kitchen,S1AndP1Are the size (the amount of this ingredient in each package) and priceSmallPackages,S2AndP2Are the size and priceLargePackages.

Given the amount of money you can spend, your task is to find the largest number of person who can serve. Note that you cannot buy only part of a package.

Input

There are at most 10 test cases. Each case begins with two integersNAndM(1 <=N& Lt; = 100, 1 & lt; =M<= 100000), the number of kinds of ingredient, and the amount of money you have. Each of the following n lines contains 6 Positive IntegersX, Y, S1, P1, S2, p2To describe one kind of ingredient (10 <=X& Lt; = 100, 1 & lt; =Y& Lt; = 100, 1 & lt; =S1& Lt; = 100, 10 & lt; =P1<= 100,S1<S2<= 100,P1<P2<= 100). The input endsN=M= 0.

Output

For each test case, print the maximal number of people you can serve.

Sample Input

2 10010 8 10 10 13 1112 20 6 10 17 243 6510 5 7 10 13 1410 5 8 11 14 1510 5 9 12 15 160 0

Sample output

52


Ask a friend to prepare n kinds of raw materials. Each raw material has six parameters: X, Y, S1, P1, S2, and P2. The meaning is: For the I raw materials, the demand for each person is X, and there is still the amount of Y, each raw material has two kinds of packaging, a small packet, package: The quantity of each packet is S1, the price is P1, the package quantity is S2, and the price is P2. Now I will give you n kinds of raw materials and M money. Please ask at most a few people.

Solution: the number of people is enumerated by the binary method. After determining whether the number of people can be satisfied, the minimum cost for each raw material is determined based on the number of people, check whether the package is out of service. If no raw material is used, you can find a full backpack. The size of the backpack is the quantity you need plus the size of the large package. Then, you can find the minimum value between need and the upper limit.


Full backpack + two points:

I am learning ....

Question connection: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 3187.

Or
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3244

# Include <cstdio> # include <cstring> # include <algorithm> # include <cmath> using namespace STD; int n, m; const int maxn = 110; const int INF = 0x3f3f3f; struct node {int S1, S2; int P1, P2; int X, Y;} t [maxn]; int cal_r () {int ret = inf; for (INT I = 1; I <= N; I ++) {If (T [I]. s1 x 1.0/T [I]. p1> = T [I]. s2 * 1.0/T [I]. p2) {int TMP = (M/T [I]. p1 * t [I]. s1) + T [I]. y; // The number of int P = tmp/T [I]. x; // Number of students; ret = min (Ret, P); // find the smallest number of students} else {Int TMP = (M/T [I]. p2 * t [I]. s2) + T [I]. y; int P = tmp/T [I]. x; ret = min (Ret, p) ;}return ret; // returns the smallest number of people;} int DP [6000000 + 20]; int cal_need (int I, int need) {int W [2], C [2]; C [0] = T [I]. p1; W [0] = T [I]. s1; C [1] = T [I]. p2; W [1] = T [I]. s2; int v = need + T [I]. s2; For (INT I = 1; I <= V; I ++) DP [I] = inf; DP [0] = 0; For (INT I = 0; I <2; I ++) // complete backpack {for (INT v = W [I]; v <= V; V ++) DP [v] = min (DP [v], DP [V-W [I] + C [I]);} int ret = inf; For (INT I = Need; I <= V; I ++) ret = min (Ret, DP [I]); return ret;} bool judge (int K) // determine whether the number of people matches the purchasing power... {Int S = 0; For (INT I = 1; I <= N; I ++) {int need = T [I]. x * k-T [I]. y; If (need <= 0) continue; int TMP = cal_need (I, need); // how much is required; S + = TMP; If (S> m) return false;} return true;} int main () {While (~ Scanf ("% d", & N, & M) & N + M) {for (INT I = 1; I <= N; I ++) scanf ("% d", & T [I]. x, & T [I]. y, & T [I]. s1, & T [I]. p1, & T [I]. s2, & T [I]. p2); int r = cal_r (); int L = 0; int ans = 0; // printf ("R % d \ n", R ); while (L <= r) {int mid = (L + r)> 1; if (Judge (MID) {ans = mid; L = Mid + 1 ;} else r = mid-1;} printf ("% d \ n", ANS);} return 0 ;}
 

 

Backpack! Come on !!!!!

Inviting friends (hdu3244 & zoj3187) full backpack + binary

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.