How many possible combinations of the variables a,b,c,d,e are possible if I know that:
a+b+c+d+e = 500
and that they are all integers and >= 0, so I know they are finite.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
@Torlack, @Jason Cohen: Recursion is a bad idea here, because there are ‘overlapping subproblems.’ I.e., If you choose
aas1andbas2, then you have 3 variables left that should add up to 497; you arrive at the same subproblem by choosingaas2andbas1. (The number of such coincidences explodes as the numbers grow.)The traditional way to attack such a problem is dynamic programming: build a table bottom-up of the solutions to the sub-problems (starting with ‘how many combinations of 1 variable add up to 0?’) then building up through iteration (the solution to ‘how many combinations of n variables add up to k?’ is the sum of the solutions to ‘how many combinations of n-1 variables add up to j?’ with 0 <= j <= k).