Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 997787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:05:26+00:00 2026-05-16T07:05:26+00:00

I’m trying to put together a system to suggest consumable kits based on a

  • 0

I’m trying to put together a system to suggest consumable kits based on a requested quantity. The challenge I’m running into is that the kits have volume/bulk discounts, so it may be cheaper for the customer to order a larger quantity because the price may be less. For example, let’s say the available kits are:

  • 25 widgets for $15
  • 10 widgets for $7
  • 5 widgets for $4
  • 1 widget for $1

Right now, for a requested quantity of 74, my algorithm will suggest 2 x 25, 2 x 10, and 4 x 1 = $48. It would be cheaper however for the customer to just order 3 x 25 = $45.

Any thoughts on how to tackle this? I’m coding in C#.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:05:27+00:00Added an answer on May 16, 2026 at 7:05 am

    That looks like standard DP (dynamic programming).

    // bestPrice is array of best prices for each amount
    // initially it's [0, INFINITY, INFINITY, INFINITY, ...]
    
    for (int i = 0; i <= 74; ++i) {
        for (Pack pack : packs) {
            // if (i + pack.amount) can be achieved with smaller price, do it
            int newPrice = bestPrice[i] + pack.price;
            if (newPrice < bestPrice[i + pack.amount]) {
                bestPrice[i + pack.amount] = newPrice;
            }
        }
    }
    

    The answer is min(bestPrice[74], bestPrice[74 + 1], ... bestPrice[74 + 25 - 1]). Overhead 25 - 1 is obviously enough, because otherwise you would remove one pack and amount would still be >= 74.

    Some links on the topic:
    http://en.wikipedia.org/wiki/Dynamic_programming
    http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProg

    edit
    You can find optimal solution if you modify it a little. Add lastPack array, so lastPack[i] is the size of the package you used to achieve amount i. I guess, you can figure out how to update pseudo-code above.

    Once algorithm is finished, you can get solution like this

    int total = 74;
    while (total > 0) {
        // package of size lastPack[total] was used to get amount 'total'
        // do whatever you want with this number here
    
        total -= lastPack[total];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to put together an Android app that will take a picture and
I'm trying to put together a layout using Bootstrap that resembles your typical OS
I'm trying to put together an image uploader. I want to upload images into
I'm trying to put together a simple RSS widget (for my wordpress blog) that
I put together a simple system so that my dad can manage a website
I am trying to put together a page that has a header that spans
I'm trying to put together a plugins system with .NET, and I'm not sure
I'm trying to put together a simple table that shows my model's data. I
I'm trying to put together a simple system for a user to generate a
I'm trying to put together an app for fun that has a scenario where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.