.
Number of test cases is no more than 80.
Sample Input
2 10240 1 30 0 1010 10231 1 11 1 21 1 41 1 81 1 161 1 321 1 641 1 1283 -1 2561 1 51219 1010 10231 1 11 1 21 1 41 1 81 1 161 1 321 1 641 1 1281 1 2561 1 51219 10
Sample output
3415i'm sorry...
Author:
Cui, Tianyi
Source:Zoj monthly, February 2009
Question: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 3164 analysis: This is the answer from Cui Tianyi, the author of the paper bag 9. This is a complicated question. It uses mu
HDU 3591 the trouble of Xiaoqian (multiple backpacks + 01 backpacks)
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3591
Question:
There is a currency system with n currencies. the nominal value of each currency is Val [I]. Now Xiaojie holds num [1], num [2],… Num [N]: 1st, 2nd... In the nth currency, buy a commodity with a value of T (t
Analysis:
We need at least X coins when we make dp1 [J] = x to repre
Link: poj 3260 Question:FJ buys things. The value of things is T. He and the seller both have n kinds of gold coins. fj wants to minimize the change of gold coins when the transaction is completed. Calculate the minimum change quantity of gold coins. FJ has a limited number of gold coins and sellers have an unlimited number of gold coins. Ideas:For a backpack, the limited number of each gold coin of Fj can be viewedMultiple backpacksThe problem is that the seller's gold coins are infinite.Full
A buys things from B. The value is m yuan, and there are n kinds of money. A has a certain amount of money, while B has an unlimited number.
The minimum number of banknotes can be used to meet the transaction requirements. For example, if a generates 50 + 25 and B finds 5, three bills are required.
A is transferred with multiple backpacks, and B is full with a backpack.
The O (n) algorithm is used to optimize multiple
About several backpacks (C language) and several backpacks (C language)
I will record and summarize several new questions about my backpack. (Refer to blog: http://blog.csdn.net/mu399/article/details/7722810 and http://blog.csdn.net/u013174702/article/details/45741395)
(1) 01 backpack:01 state transition equation f [I, j] = Max {f [I-1, j-Wi] + Pi, f [I-1, j]} f [I, j] indicates the maximum value that can b
number of coins involved in a payment and change-making. if it is impossible for Farmer John to pay and receive exact change, output-1.Sample Input3 705 25 505 2 1Sample output3
Question:
FJ buys things. The value of things is T. He and the seller both have n kinds of gold coins. fj wants to minimize the change of gold coins when the transaction is completed.
Calculate the minimum change quantity of gold coins. FJ has a limited number of gold coins and an unlimited number of profitors.
Ideas:
F
space-separated integers, respectively C1, C2,..., CNThe end of the input is a double 0.
Outputoutput one line for each test case like this "case X: Y": X presents the Xth test case and Y presents the minimum number of coins. if it is impossible to pay and receive exact change, output-1.
Sample Input
3 705 25 505 2 10 0
Sample output
Case 1: 3
The currency system has n different denominations of money. The values of each currency are V1, V2 ,..., vn: a person wants to buy value and t goods, an
What are multiple backpacks?
There are N items and a backpack with a capacity of V. A maximum of Mi pieces are available for the I-th item. The space consumed by each item is Ci, and the value is Wi. Solving which items are loaded into a backpack makes the total space consumed by these items not exceedBackpack capacity, and the total value is the largest.
Among them, if Mi * Ci> = V, then multiple backpacks
P09: questions about backpacks
All the above problems involve the greatest value that can be obtained under the limitation of the capacity (cost) of the backpack. However, there are still many flexible questions about the backpack. It is worth mentioning here. However, I believe that as long as I thoroughly understand how to find the greatest value of the knapsack problem, even if the question method changes, it is not difficult to come upAlgorithm.
This is a typical problem of multiple backpacks. At the beginning of writing, I used the simplest solution of multiple backpacks, that is, converting multiple backpacks into 01 backpacks. The result was no more than once. It was then converted into a full backpack and A 01 backpack for solving the problem. However, the
Tags: Multiple backpacks Link: poj 1276 Question: The known amount cash.Number and nominal value of currencies with the same nominal value,You can use the given currency to generate Less than or equal to the maximum cash amount Analysis: Because the nominal value and quantity of each currency are known, it can be convertedMultiple backpacks,The capacity of the backpack is cash, The value and cost of ea
HDU 2191 mourns the victims of the 512 Wenchuan earthquake-Cherish the present and be grateful for your life (multiple backpacks)
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2191
Question:
Assume that you have funds of N yuan, and then there are m kinds of rice. The price for each type of rice is cost [I], the weight is Val [I], and the quantity is num [I]. now, how much rice can you buy with N yuan?
Analysis:
This is a typical problem of multiple
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1171
Meaning: There are n kinds of items, which give the value and quantity of each item. Divide these items into two equal portions A and B as much as possible and Output A and B.
The primary function can be used, but the most direct method should be multiple backpacks.
In the case of a primary function, the value is also calculated by half of the total value, from half to small enumeration until B is
enterprising and hard.
We also want to thank the wealth that the pain and hardships have brought us ~
Input data first contains a positive integer c, indicating that there are C test cases. The first line of each test case is two integers n and M (1 Output for each group of test data, please output the maximum weight of the rice that can be purchased. You can assume that the cost is not only for all the rice, but you don't have to finish the cost. The output of each instance occupies one row
infinity.
I started to think that the data is small (I didn't see the question clearly). In fact, the big thing is, I used the 01 backpack to do it, and decisively timed out.
So I changed to the binary optimized 01 backpack + full backpack with multiple backpacks. It is a template. It seems that only the optimized 01 backpack can be used, but I don't know how to do it.
The following is a simulation of the problem of multiple
/* Multiple backpacks, which are converted into 01 backpacks using the binary splitting method */# include
/* Completely converted from a backpack to a repeated 01 backpack */# include
/* The two-dimensional cost is much deformed. The triple cycle is hard to grasp. */# Include
This is my first thought of as a mother function, but it is said that when the mother function uses TLE, multiple backpacks are decisive. Here we use multiple backpacks, obviously we cannot directly output DP [N, in this case, the result is wrong. How can we find the type. If (DP [I]) ++ C ;?????? Can this be done ???? No, this is the meaning of DP [I]. DP [I] represents the greatest value that can be found
Http://poj.org/problem? Id = 1276
There is a cash machine containing T currencies with a nominal value of N [I], each with a V [I. The maximum amount that can be exchanged if the exchange amount does not exceed the cash RMB.
Multiple backpacks are converted into 01 backpacks, which require binary optimization. 9. The answer to this story is quite good. Add a coefficient before the value of each item and en
Link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2844
The meaning of this question is only after reading it for a long time.
N and m respectively represent n silver coins. the purchased items are no higher than m yuan.
Then we will give you 2 * n pieces of data. The first n pieces are values, and the last n pieces are numbers.
Then I asked you, how many groups of coins can be combined not greater than m?
That is, there are several situations of 1 to M.
There are two cases for this quest
Question address: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1963
Find the maximum profit that can be obtained each time, multiple backpacks.
Here we will use a technique. The question "V [I]" is a multiple of 1000, so it can be divided by 1000.
The Code is as follows:
# Include
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.