Hangdian 1248 cold ice throne (full backpack)

Source: Internet
Author: User

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

Frozen throne Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 10792 accepted submission (s): 5476

Problem description the Lich King of the undead family sends a salary pull, and the Death Knight receives a N yuan bill (Remember, there is only one bill). To prevent him from dying frequently during the battle, he decided to buy some items for himself, so he came to the top store.

Death Knight: "I want to buy items! "

Taobao Merchants: "We have three items here: one for 150 blood bottles, one for 200 magic medicines, and one for 350 for invincible potions ."

Death Knight: "OK, give me a blood bottle ."

Then he took out the n-dollar bill and handed it to the goblin merchant.

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

Death Knight :"......"

The Death Knight thought, instead of sending money as a tip to him, it would be better to buy more items on his own. He would like to buy them all in the future and put them at home early, but try to make him as little tip as possible.

Now, the Death Knight hopes that you can help him calculate the minimum tip he wants to tip the goblin merchant.
The first line of input data is an integer T (1 <= T <= 100), representing the number of test data. then there is T-row test data. Each test data contains only one positive integer N (1 <= n <= 10000), and N represents the nominal value of the money in the hands of the Death Knight.

Note: There are only three items described in the topic.
 
Output for each group of test data, please output the minimum amount of money the Death Knight will waste to the goblin merchant as a tip.
 
Sample Input
2900250
 
Sample output
050
 


According to the meaning of the question, you can use a full backpack to do this. Because there are only three kinds of potions, and there are no other ones, you can think that their volume is the cost.

AC code:

#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;int dp[10005];int main(){    int t,n,i,j;    int c[3]={150,200,350},w[3]={150,200,350};    scanf("%d",&t);    while(t--)    {        memset(dp,0,sizeof(dp));        scanf("%d",&n);        for(i=0;i<3;i++)        {            for(j=1;j<=n;j++)            {                if(j>=c[i])  //                    dp[j]=max(dp[j],dp[j-c[i]]+w[i]);            }        }        printf("%d\n",n-dp[n]);    }    return 0;}




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.