Computational search in hashtable

Hi experts,
I have the following situation. I have 25 apples and want to give away these apples to a list of people who need them stored in hashtable. Each of these people has indicated the quantity which they need. How to do give away exactly 25 apples to those who need them?
Hashtable<String,Object> h = new Hashtable<String,Object>();
h.put("andy", new Integer(1));
h.put("angie", new Integer(2));
h.put("eddie", new Integer(3));
h.put("tammy", new Integer(4));
h.put("edwin", new Integer(5));
h.put("dolly", new Integer(6));
h.put("sally", new Integer(7));
h.put("silly", new Integer(8));
h.put("zorro", new Integer(9));
h.put("sam", new Integer(10));
In other words, any hints how to search the hashtable in a way that the input is 25 and the output is a list of elements which its total values match 25 or closest to 25?
Thank you in advance.

Are you assuming that you have to fill an entire request (i.e., Eddie must get 3 apples or none at all)? Is there a reason you're using a hashtable for this?
It sounds like you're trying to solve a one-dimensional packing problem: given a set of numbers N_1, N_2, ... N_n, you want a subset of those numbers can be summed to total a given value V. Is this true?

Similar Messages

  • ITunes, new computer, search/consolidate all songs?

    I just went from a prehistoric iBook G4 to a lightning-fast MacBook Pro.
    The new computer was a gift, so 'setup assistant' has already been run, and I don't want to reinstall the OS, seeing as my mum added her Mac programs (Word, etc) for which I don't have disks.
    The problem is: my old iBook didn't have memory, so all my stuff is already on an external hard drive. I want to find a way that the new iTunes will read and consolidate all of the existing songs on my external hard drive. I've read forum posts, and in theory there should be a 'search' function, though I have yet to find it on the new OS.
    I backup frequently, so I could use backup disks, but considering that I have 80gig of music this would involve going to the hard drive, deleting the existing music, then re-importing it (I wouldn't have room on my hard drive for the old 80gig + the same old re-imported 80-gig's worth...). Big pain in the tuckus, and counterproductive.
    There must be a way to have iTunes search for and consolidate existing music on a hard drive.
    I seem to remember having this function on the old OS, 'twould be a bummer not to have it on the new one. I already notice that in internet settings 'Use Interference Robustness" has disappeared, meaning I can't connect wirelessly to the internet using the MacBook Pro.
    Not having internet or music will make me beg to have my old iBook-PowerPC back....
    I have also used my MacOS help function with little luck...

    Well you should be able to import songs by clicking on "File" and "import folder" then you can select the source such as your external hard drive. Itunes will then import your music and, if neccesary, convert them to the MP3 format.
    Hope this helps!

  • Searching in Hashtable

    Hi,
    I have a problem to search in a Hashtable.
    Someone can help me?
    Thanks

    Probably; many Hashtable problems have been solved in this forum already. If there's not a solution to your problem in an old thread already, I believe you should go ahead and describe it as well and fully as you can, and also what you did to solve it already, so nobody needs to post a suggestion you already tried.
    Message was edited by: OleVV
    OleVV

  • Downloaded files aren't on my computer (searched everywhere)

    Hi,
    I am having trouble with some PDF files I downloaded.
    Completely downloaded about 12 files I needed, but from the download viewer I only moved the 4 I needed to work with into a folder. I figured the rest were stored in some temporary folder and would later be accessible.
    However, they are nowhere on my computer.
    Interestingly, I don't have this problem with recent image and font files I downloaded.
    Any suggestions?
    Thanks!
    - Aaron

    Its good to have both, a time machine backup, AND a second cloned HD.
    If your HD ever dies on you, you can in a matter of 20 mins, install the old HD and be up and running again quickly.
    Its extremely important to have MULTIPLE backups, so many people have been so upset at losing massive amounts of data, because they "had a backup HD" for their data, but when that died etc, its gone.
    1 backup is never enough, and the data on your computer "doesnt count" as a backup.

  • HT1338 why is my computer searching for my home wi-fi?

    While on vacation my computer scanned for local wi-fi, why does it continue to scan at home with my secure wi-fi?

    This is normal. Your device is NOT constantly looking but only looks again when you click the airport icon. You may want to change networks or you may have come into the range of a new network that was not previously in the list, you see.
    This is the case whether the box is checked or unchecked pertaining to "asking before joining new networks" in the system preferences.
    Think of the light which only comes on when the refrigertor door is opened.

  • Reading Values from a Hashtable.Please guideu

    Chaps,
    I am in a strange situation
    I am having a hashtable with the flwg values
    Entertainment Games
    Entertainment Video
    PIM Calculator
    Entertainment Jump
    Settings Set
    Entertainment Poker
    Now,I need to search this hashtable for the
    Object 'Entertainment' and whatever is the
    value of this,is put in an Array
    for this I am using:
    String s[];
    Enumeration e;
    for(int i=0; i<ht.size(); i++){
    String s = (String)ht.get("Entertainment");
    // I am stuck after this? Can some one please help?       
             

    Object value = ht.get("Entertainment");
    But if you are doing this (I can't tell if this is what you're doing from your first post, though):
    ht.put("Entertainment", onething);
    ht.put("Entertainment", anotherthing);
    ht.put("Entertainment", athirdthing);
    Then there will only be athirdthing in the table, cuz it'll overwrite the previous values.

  • The remote server returned an error: (503) Server Unavailable in search service

    Hi
    I got this error message: when applying toplogy to search service
    I am applying admin component : SPINDEX Server
    crawl component-0 to : same index server spindex server
    in sharepoint farm has
    1 applicationserver
    1 index server
    1 wfe server
    1 db server
    I prepared like this try to configure search service on index server
    Microsoft.Office.Server.Search.Administration.SearchConfigWizard+SearchConfigWizardException: Topology provisioning failed due to an error.Object reference not set to an instance of an object. at Microsoft.Office.Server.Search.Administration.SearchConfigWizard.WaitForTopologyTimerJobToFinish()
    at Microsoft.Office.Server.Search.Administration.SearchConfigWizard.UpdateSearchApp() at Microsoft.Office.Server.Search.Administration.SearchConfigWizard.ProvisionSearchServiceApplication() at Microsoft.Office.Server.Search.Administration.SearchConfigurationJobDefinition.ExecuteTimerJob()
    in the event viewer I get this error
    Application Server Administration job failed for service instance Microsoft.Office.Server.Search.Administration.SearchServiceInstance (e8ab042b-f884-4957-b328-631ba8bcb4a1).
    Reason: The remote server returned an error: (503) Server Unavailable.
    Technical Support Details:
    System.Net.WebException: The remote server returned an error: (503) Server Unavailable.
       at Microsoft.Office.Server.Search.Administration.SearchServiceInstance.Synchronize()
       at Microsoft.Office.Server.Administration.ApplicationServerJob.ProvisionLocalSharedServiceInstances(Boolean isAdministrationServiceJob)
    adil

    Hi
    when  i set  crawl component,administration component to local computer  search service working properly
    but when i scale out search service application
    change above components  to diffrent server i get following error
    Errors were encountered during the
    configuration of the Search Service Application.
    Microsoft.Office.Server.Search.Administration.SearchConfigWizard+SearchConfigWizardException:
    Topology provisioning failed due to an error.Object reference not set to an
    instance of an object. at
    Microsoft.Office.Server.Search.Administration.SearchConfigWizard.WaitForTopologyTimerJobToFinish()
    at
    Microsoft.Office.Server.Search.Administration.SearchConfigWizard.UpdateSearchApp()
    at
    Microsoft.Office.Server.Search.Administration.SearchConfigWizard.ProvisionSearchServiceApplication()
    at
    Microsoft.Office.Server.Search.Administration.SearchConfigurationJobDefinition.ExecuteTimerJob()
    3/23/2014
    10:32:20 AM
    and in event viewer
    Application Server Administration job failed for service instance Microsoft.Office.Server.Search.Administration.SearchServiceInstance (e8ab042b-f884-4957-b328-631ba8bcb4a1).
    Reason: The remote server returned an error: (503) Server Unavailable.
    Technical Support Details:
    System.Net.WebException: The remote server returned an error: (503) Server Unavailable.
       at Microsoft.Office.Server.Search.Administration.SearchServiceInstance.Synchronize()
       at Microsoft.Office.Server.Administration.ApplicationServerJob.ProvisionLocalSharedServiceInstances(Boolean isAdministrationServiceJob)
    adil

  • HP OfficeJet Pro 8500A e-all-in-one has stopped printing from my computer

    My 8500e has been working fine for months.  My computer is an HP HPE Phoenix h9t.  I'm running Windows 7.  The printer is set up on the wireless network.  This week it just quit printing.  I have uninstalled, reinstalled, downloaded diagnostics.  You name it, I've done it.  Nothing in my network or computer setup has changed.  I can set up the wireless on the printer itself--it sees my wifi network, I enter the security code, I can print the wireless network test report from the printer itself, everything is pass and excellent. 
    Then when I install the software on the computer, tell it I have an IP address from the printer, which is connected wirelessly, I put in the IP address from the display screen on the printer and computer searches then says it can't find it.  I have also reset the printer to factory defaults.  No go.
    We are definitely on the same, secure home network.  However, now when I enter the IP address that the printer is giving me into IE, to see if I can see it that way, it can't find it.  Is that where the problem is?  How do I fix that?
    I am WAY beyond frustrated, my work is frighteningly behind, and my husband can't airprint from his iPad.  I have searched the forum and can't figure this out. 
    Thanks for reading through my litany of woes...

    Download and run this utility: http://h10025.www1.hp.com/ewfrf/wc/softwareDownloadIndex?softwareitem=mp-104282-2&cc=us&dlc=en&lc=en...
    What does it say?
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • Add Computer Name to Format-Table output?

    I'm trying to run a simple little script to check against all the servers in a specific Active Directory OU.  It just runs a quick WMI check for the account that the services are starting up as.
    I need to add the name of the computer to the output.
    $strFilter = "computer"
    $objDomain = New-Object System.DirectoryServices.DirectoryEntry
    $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
    $objSearcher.SearchRoot = "LDAP://OU=Servers,OU=IT,DC=mydomain,DC=mytld"
    $objSearcher.SearchScope = "Subtree"
    $objSearcher.PageSize = 20
    $objSearcher.Filter = "(objectCategory=$strFilter)"
    $colResults = $objSearcher.FindAll()
    foreach ($i in $colResults)
    $objComputer = $i.GetDirectoryEntry()
    Get-WmiObject win32_service -ComputerName $objComputer.name | where {$_.startname -like '*mydomain*'} | ft name, startname, startmode
    Output is like:
    name startname
    startmode
    MSSQL$GIS mydomain\serviceaccount
    Auto
    SQLAGENT$GIS
    mydomain\serviceaccount
    Auto
    etc

    This is actually faster and eliminates all of the code that you are not using.  Because of the "$obj" I can tell that you copied some very old code.  We don't really do that in PowerShell.
    This is more concise and easier to understand as well as being faster.
    $searcher =[adsisearcher]'objectCategory=computer'
    #$searcher.SearchRoot='LDAP://OU=Servers,OU=IT,DC=mydomain,DC=mytld'
    $searcher.FindAll() |
    ForEach-Object{
    $computer=$_.Properties['name'][0]
    Get-WmiObject win32_service -ComputerName $computer -Filter "startname like '%TESTNET%'"
    } |
    ft PsComputerName, name, startname, startmode
    ¯\_(ツ)_/¯

  • New Computer to add to existing network

    Hello all,
    I had a wireless network at home with 2 pcs. One tower pc (ethernet cable to router) and a laptop. The tower pc has just been replaced and now I want to get it onto the existing network. Do I have to set the whole lot up again? The router and network connections are still ok (I'm using the laptop now!) I did try running the linksys setup again but it's failing - my guess is that it won't set it up if it already exists. I put the ethernet cable inito my new pc but the system has not recognised any new hardrware. Sorry to be lazy by asking for help but I'm hoping someone on here has been through the same problem. Any help would be much appreciated.
    Regards 
    G

    if two computers are already working through the router , there is no need to run the setup again..for a hardwired computer..just connect the computer to the LAN port of the router and it should work fine..for a wireless computer , search for the wireless network and connect to it..

  • Gpedit , My computer not the local computer; from local computer access others ..

     gpedit ,   My computer not the local computer? Since it put auto at the Other's like place.
    From  local computer search access others pc, nothing empty to chose neither.

    Whatever the Following Computer in the up photo is not the LOCAL=My Computer is an arcane of the OS .
    You right, mmc  / domain as the capture would work for PC manage.  That implying this PC had
    been worked on a domain by default since i did searchable other PCs on the SPACE of workgroup ! Four months ago.
    To have the domain configure got error below , Router configured Dynamic dns successfully , why reminded a 192.168.1.1 on the DNS IP ? It is router's defaulted.  Sharing IP with DNS remote server ?AC DC not forwarded , how to ?
    Program on powershell how to run well for getting _ldap._tcp.dc._msdcs.domainname.domain by the way, for weight, port, priority result etc ?

  • How to search all my files?

    Will someone tell me how I can search for all of the photos on my laptop through finder? I recently discovered a huge bug with my iphoto, where pictures were not actually being deleted from my computer. So now have hidden files shown and was able to find said files, and delete them. Now that I know there were photos I did not want saved, I want to see a finder page with EVERY photo on my mac. If I search "all images" it shows 200 images, I know there thousands of photos saved on my mac. I want to see every single one of them. On previous versions of OSX I think I just had to click "search system files" or "include hidden files" or somthing along those lines...
    I want, a page, in finder, with every photo on my mac, so I can see what else is lingering here (I use my phone to "scan" confidential documents sometimes).
    does anyone know how I would accomplish this?

    I am doing it exactly as you have shown. the whole issue arose because I was unable to see files in my finder that were showing up in my spotlight. The second line of this terminal window shows an example of what I mean. See how the files are not displayed in finder?
    so I found the culprit files by using the command:
    defaults write com.apple.Finder AppleShowAllFiles YES
    and restarting terminal.
    Now I want to see what other files I thought were deleted still remaing on my computer. searching just "jpg" as you described is not showing my all of the jpgs, it doesn't even show me all of the non-hidden jpg files, let alone ALL of them, which is what I want...

  • Search for purchased/bought music/articles fails!

    hi,
    just bought two albums in the music store. now i activated my second computer searched for purchased music and it only found 4 of more than 20 purchased tracks. when i try to buy it again it first said that i already bought it and i can sync (which didn't work then) or i should burn the music to a cd/dvd and transfer it manually. nice function crappy implementation!
    sorry for the complicated subject with all the slashes. got a german version of itunes and don't know how the english option for that function is called.
    regards,
    eric.

    I switched to German as system language and now see what you mean.
    'Computer aktivieren...' means to authorize your computer to play purchased music.
    You are allowed to download purchased music only once.
    It looks like 4 of the songs were not downloaded yet on computer 1.
    So when you authorized your second computer, it downloaded the missing songs.
    If the above is true, these 4 songs are missing on computer 1.
    Um zu verstehen was Aktivieren bedeutet, bitte zuerst mal diese seite lesen (please read the Authorization FAQ first)
    Just transfer the purchased songs (using a memory stick, external drive, ethernet, CD or DVD) from 1 computer to the other.
    Because you're allowed to download the songs only once it is highly recommended to create a backup copy.
    Here is the link to the German version of the Terms of Service:
    Dienstleistungsbedingungen (achte auf Kapitel 9!!)
    M
    17' iMac 800 MHz, 768 MB RAM, 200 GB HD, DL burner   Mac OS X (10.4.8)   iTunes 7.0.2

  • I backed-up my iphone to my computer and now I can't find any of my music, does anyone know where it went?

    I backed-up my iphone 3GS to my computer and now I can't find any of my music.  I doesn't seem to be anywhere in itunes.  Can anyone help me?

    Backing up the iPhone to the computer won't transfer the music to it; to do that, you need to use the Transfer Purchases function. If you're looking for music already on the computer, search it for files with an extension of mp3, m4a, or m4p.
    (83190)

  • Inconsistent SEARCH FUNCTION in Lion Mail

    I have a note book Pro with Lion OS X 10.7.2.
    Since I have Lion when I use the mail search function, I cannot control my search.
    Sometime I can search " by" or  "from", sometime  I cannot access that way of searching
    Some other times I can search by selecting People, Mailbox or subject...
    At no time i have the control of choosing the way I want to organize my search
    It should exist a search function that would enable to choose the best way to make a search and to refine that search
    Any suggestion to control your search?

    Don't take this the wrong way, but stop wasting your time. I spent 2 hours at my local Apple store yesterday and at the end of it all was told there was an issue with mail search in Lion and that Apple was aware of it.
    I went so far as to bring an identical computer loaded with the same number of mail messages (25,000+) running snow leopard instead of Lion, set the computers side by side and time after time the mail in Leopard worked perfectly while Lion found few if any mail messages at all. For example when we searched the term "computer" search would bring up 2477 found on Snow Leopard and none in Lion. Just one example.
    The Apple Genius Bar guy was apologetic and tried all of the following during my 2 hour visit:
    Rebuild spotlight
    Reinstall Lion
    Rebuild Indexes
    export mail
    import mail
    Reset Mail app from
    use migration assistant to set up Mail from Leopard to Lion
    Remove and rebuild envelope
    delete mail plist
    Use Terminal to reset indexes
    Throw away saved search preferences
    No Joy
    Funny though how well mail worked perfectly with a few hundred sample emails on computers in store.
    Lastly the theory that we agreed on was that perhaps I had too many emails and or attachments in inbox and Lion could not deal with it.
    Looking at alternative like Postbox or Thunderbird until fix is implemented by Apple.
    Hope this helps.

Maybe you are looking for

  • Windows 7 installation via an external usb dvd drive

    Hello everybody ! So here is my problem : I have replace my superdrive by a SSD disk and re instal Lion on it   I steel got my orginal hard drive and I use it to save all my documents ... From here everythings it's ok but ... I need to instal windows

  • No SID found for value '0CURR' of characteristic 0CURRENCY

    Hello dear friends I am getting this above error message 'No SID found for value '0CURR' of characteristic 0CURRENCY' when i am trying to load data in my cube from an ODS. For the Keyfigure that is using the currency  i had to write the following rou

  • Officejet 6500 709e LCD display doesn't display all pixels

    A week ago my wired printer stopped displaying all the pixels on the LCD display.  I can't, at this point, understand anyhting on the first or second lines.  So I don't know how much ink I have in each cartridge (which usually shows on the second lin

  • Import CD question?

    Hi , One thing I can never figure out is how to import a cd to say "my cd's" folder that I made within playlists. I imported a CD and all the tracks or album is only visible under "library" music but there's a ton of stuff in there like radio station

  • Calling abap web service from webdynpro

    hi, i have a problem in that i am trying to call an ABAP web service published from r/3 in webdynpro. when i browse to the url generated by the r/3 application server it asks for my r/3 user name and password (not to be confused with http proxy user