Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: maximum toys

  1. #1
    simar is offline Member
    Join Date
    Aug 2014
    Posts
    27
    Rep Power
    0

    Default maximum toys

    plz any one help me out i have an assignment wil u plz help me tommorow is its last submission date . so plz.....
    here it is....jst tell me the logic how can it b solved,,,

    mark and jane are very happy having their first kid.their son is fond of toys so mark wants to buy some their are N different toys in front of him ,having tagged their price.but he has only $k he wants to maximize the toys he buys with this money now you are marks best friend and have to help him buy as many as passible.

    solve the above problem with following constraint.

    buy maximum toys with maximum money left

    note. a toy cannt b bought multiple times but multiple toys can hav sam price.

    example
    input.
    mark has money:50
    available toys:{1,12,5,111,1000,200,10,9,6,7,4}

    output
    buy maximum no. of toys with maximum money left:
    output- {7,8}
    explanation:
    maximum no. of toys =7 {1,5,10,9,6,7,4}
    saving =8

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: maximum toys

    How would you do this by hand, on paper?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: maximum toys

    That's an ordinary knapsack problem (Google is your friend).

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    simar is offline Member
    Join Date
    Aug 2014
    Posts
    27
    Rep Power
    0

    Default Re: maximum toys

    here is a code of above problem can u plz solve it error is main class not found
    candidatecode.candidatecode class wasn't found in candidatecode project...
    Java Code:
    import java.util.Scanner;
    import java.util.Arrays;
    public class Candidatecode {
    
        public static int[] getmaxtoysithmaxsaving(int money,int[] toys)
        {
            Scanner input=new Scanner(System.in);
            int n;
            int numberoftoyscanbuy=0;
                    n=input.nextInt();
                    money=input.nextInt();
                    toys=new int[n];
                    for(int count=1;count<=n;++count)
                        toys[count-1]=input.nextInt();
                    Arrays.sort(toys);
                    for(int count=1;count<=n;++count)
                    {
                        money-=toys[count];
                        if(money<0)
                            break;
                        numberoftoyscanbuy++;
                     }
                    System.out.println(numberoftoyscanbuy);
        }
    }
    Last edited by simar; 11-09-2014 at 01:33 PM. Reason: added [code] ... [/code] tags

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: maximum toys

    I must be missing something here because this problem seems trivial as stated. The term "knapsack problem" seems to imply a more complicated solution (akin to bin stacking).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: maximum toys

    Quote Originally Posted by jim829 View Post
    I must be missing something here because this problem seems trivial as stated. The term "knapsack problem" seems to imply a more complicated solution (akin to bin stacking).
    You're not missing anything; the OP is missing the point: his/her algorithm simply collects as many of the cheapest toys as possible (which is not a knapsack solution to the problem).

    kind regards,

    Jos

    edit: I just noticed: there is one toy for each type and the aim of the game is to collect as many toys as possible; this reduces the problem to the solution given by the OP.
    Last edited by JosAH; 11-08-2014 at 06:01 PM.
    Build a wall around Donald Trump; I'll pay for it.

  7. #7
    simar is offline Member
    Join Date
    Aug 2014
    Posts
    27
    Rep Power
    0

    Default Re: maximum toys

    can u plz help me to solve it error is main class not found
    candidatecode.candidatecode class wasn't found in candidatecode project

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: maximum toys

    Java is case sensitive. Check that the class name's spelling matches the class name used with the java command.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: maximum toys

    Quote Originally Posted by simar View Post
    can u plz help me to solve it error is main class not found
    candidatecode.candidatecode class wasn't found in candidatecode project
    You named your class Candidatecode, not candidatecode; the name of the source file should be the same.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: maximum toys

    Quote Originally Posted by simar View Post
    can u plz ...
    Can you please not write like a semi-educated twit?

    db
    gimbal2 likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Toys that we still play with
    By End Of All in forum Entertainment
    Replies: 1
    Last Post: 01-14-2016, 07:53 AM
  2. Finding maximum..
    By putrify in forum New To Java
    Replies: 25
    Last Post: 09-06-2011, 05:55 AM
  3. Maximum subsequence
    By dxg in forum New To Java
    Replies: 12
    Last Post: 09-25-2010, 05:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •