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 8168459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:32:03+00:00 2026-06-06T20:32:03+00:00

(Motivation: Consider a problem where you have to select a sports team from a

  • 0

(Motivation: Consider a problem where you have to select a sports team from a population of available players. Each player has a certain skill level exactly proportional to their salary expectation, and you want the total of this skill/salary level to exactly match your total salary cap.)

I need to write the following function:

 bool possibleAssignment(int N, int M, int T, vector<int> H);

The input constraints are:

  • 0 < N <= 50
  • 0 < M <= 50
  • 0 < T <= 2500
  • H.size() == N + 1
  • Forall i, 0 <= H[i] <= M

possibleAssign returns true iff an array X of M ints can be assigned with the following three constraints:

  1. Forall i, 0 <= X[i] <= N
  2. Forall v, the number of elements of X with value v is <= H[v]
  3. The sum of X is T

By what algorithm or method can I implement possibleAssign?

  • 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-06-06T20:32:05+00:00Added an answer on June 6, 2026 at 8:32 pm

    This problem seems reduceable from the Subset Sum Problem, or it is better known variant: knapsack problem, which are NP-Hard, so there is no known polynomial solution for it.

    However, it seems T is small enough, and luckily, there is a pseudo polynomial solution to the problem using DP.

    Because the problem is already similar to the knapsack problem, I’d try to reduce the problem to fit the knapsack problem, and then invoke the DP algorithm for finding the best solution for the knapsack problem:

    I’d first filter the list, keep only H[v] elements with value v. Now, set the elemets as follows:

    value(x) = 1
    weight(x) = x
    Bag size = T
    

    This will get you going – giving you the maximal number of elements that can be assigned with salary constraint T

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Motivation: I have fxcop integrated in the build process, which makes fxcopcmd.exe run each
I have a service that accepts callbacks from a provider. Motivation : I do
My motivation for chaining my class constructors here is so that I have a
Motivation: I have a function func(const string& s); { //... } of course this
Motivation and Problem There are several libraries for generating html markup strings using ruby
the motivation is for checking what has changed in a deeply nest map, kind
Motivation : I want be able to retrieve and view Certificates from a Windows
Motivation From time to time I need some different colors for images used in
Motivation I have a long-running boolean function which should be executed in an array
Motivation: I'm solving problems that are caused by strange/mutated/odd/perverse cookies in ruby-on-rails. I have

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.