HDU 1248 Ice Throne-full backpack or memory search

Source: Internet
Author: User

Ice ThroneTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 13001 Accepted Submission (s): 6620


Problem description The undead Lich King, the Death Knight got an n-dollar bill (remember, only a note), in order to prevent his frequent death in the battle, he decided to buy himself some props, so he came to the Goblin store before.

Death Knight: "I want to buy props!"

Goblin businessman: "We have three kinds of props here, 150 pieces of blood bottle, a magic medicine 200 pieces of one, invincible potion 350 pieces of one."

Death Knight: "All Right, give me a blood bottle."

He took out the N-dollar bill and handed it to the Goblin merchant.

Goblin businessman: "I forgot to remind you that we do not have the habit of looking for guests money here, more money we all when the tip received, hey."

Death Knight: "..."

Death Knight thought, rather than the money as a tip to send him as much as he bought a little props, anyway, after all to buy, early bought to put in the home, but to try to make him less to earn tips.

Now the Death Knight wants you to help him figure out how much he should tip the Goblin merchant at least.
The first line of input data is an integer T (1<=t<=100), which represents the number of test data. Then the T-line test data, each test data contains only a positive integer n (1<=n<=10000), n represents the face value of the money in the Death Knight's hand.

Note: The Goblin store has only three items described in the title.

Output for each set of test data, please export the Death Knight at least how much money to waste to the goblin businessman as a tip.

Sample Input
2900250

Sample Output
050 Memory Search Code:
/*problem:1248 (Ice throne)     Judge status:acceptedrunid:14251353    language:g++    author:2486code Render Stat Us:rendered by Hdoj g++ Code Render Version 0.01 beta*/#include <cstdio> #include <cstring> #include <algor ithm>using namespace Std;const int maxn=1e4+5;int t,n;int dp[maxn];int s[3]={150,200,350};int dfs (int S) {    if (dp[ S]!=-1) return dp[s];    int ans=0;    for (int i=0;i<3;i++) {        if (s-s[i]<0) continue;//money is not enough to buy something        Ans=max (Dfs (s-s[i]) +s[i],ans);    }    return Dp[s]=ans;} int main () {scanf ("%d", &t), memset (Dp,-1,sizeof (DP)), while (t--) {    scanf ("%d", &n);    DFS (n);    printf ("%d\n", N-dp[n]);} return 0;}


Full Backpack Code:
/*problem:1248 (Ice throne)     Judge status:acceptedrunid:14251499    language:g++    author:2486code Render Stat Us:rendered by Hdoj g++ Code Render Version 0.01 beta*/#include <cstdio> #include <cstring> #include <algor ithm>using namespace Std;const int maxn=1e4+5;int t,n;int dp[maxn];int s[3]= {150,200,350};int main () {    scanf ("%d ", &t);    Memset (Dp,0,sizeof (DP));    while (t--) {        scanf ("%d", &n);        for (int i=0;i<3;i++) {for            (int j=s[i];j<=n;j++) {                Dp[j]=max (dp[j],dp[j-s[i]]+s[i]);            }        }        printf ("%d\n", N-dp[n]);    }    return 0;}




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 1248 Ice Throne-full backpack or memory search

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.