Hdu1248 full backpack DP

Source: Internet
Author: User



Frozen throne

Time Limit: 2000/1000 MS
(Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 3430 accepted submission (s): 1565


Problem description

The Lich King of the undead family sends a salary,
Death server receives n
Dollar Bill (
Remember,
Only one banknote ),
To prevent yourself from dying frequently in the battle,
He decided to buy some items for himself,
So he came to the dejing commodity store.


Death Knight :"
I want to buy items! "


Goblin Merchants :"
We have three items,
Blood bottle 150
Block one,
Magic medicine 200
Block one,
Invincible potion 350
Block one ."


Death Knight :"
Okay,
Give me a blood bottle ."


Then he took out the N
The dollar bill is handed to the Taobao merchants.


Goblin Merchants :"
I forgot to remind you,
We don't have the habit of looking for money here,
We accept a tip for a lot of money,
Hey ."


Death Knight :"......"


Death Knight thought,
Instead of sending money as a tip, it is better to buy more items by yourself,
I will buy it all later,
I bought it early and put it at home,
But try to make him as little tip as possible.


Now the Death Knight hopes that you can help him calculate,
At least how much tip he wants to tip the goblin merchant.

 

 

Input

The first line of the input data is an integer T (1 <= T <= 100 ),
Indicates the number of test data.
Then T
Row test data,
Each test data contains only one positive integer N (1 <= n <= 10000), n
The nominal value of the money in the hands of the Death Knight.


Note:
The Goblin store only contains three items described in the question.

 

 

Output

For each group of test data,
Please export the minimum amount of money the Death Knight will waste to the goblin merchant as a tip.

 

 

Sample Input

2

900

250

 

 

Sample output

0

50

 

 

Full backpack exercises
......

The Code is as follows:
:

 

# Include <stdio. h> <br/> # include <string. h> <br/> inline int max (int A, int B) <br/>{< br/> return A> B? A: B; <br/>}< br/> int main () <br/> {<br/> int T, P [4], V [4], DP [10005]; <br/> int I, j, N; <br/> scanf ("% d", & T ); <br/> P [1] = V [1] = 150; <br/> P [2] = V [2] = 200; <br/> P [3] = V [3] = 350; <br/> while (t --) <br/>{< br/> memset (DP, 0, sizeof (DP); <br/> scanf ("% d", & N); <br/> for (I = 1; I <= N; ++ I) <br/> {<br/> for (j = 1; j <= 3; ++ J) <br/> {<br/> if (I> = P [J]) DP [I] = max (DP [I], DP [I-P [J] + V [J]); <br/>}< br/> printf ("% d/N ", n-DP [N]); <br/>}< br/> return 0; <br/>}< br/>

 

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.