July 10th, 2003, 10:14 AM
Join Date: Oct 2002
Time spent in forums: 46 m 52 sec
Reputation Power: 12
Sums and constraints
straight to the problem:
- We can only use numbers from 1 to 4.
- We have a sum p to reach, as large as we want
- We have a max number of addends s, as large as we want
- We have to calculate the min addend and the max addend we have to use to reach the sum, if it is ever possible to be reached.
Note: we can take no care of commutation: a+b === b+a
s = 2
p = 4
Possible sums: (2+2, 1+3)
So solution is: (1, 3)
s = 3
p = 6
Possible sums: (2+2+2, 4+1+1, 3+2+1)
So solution is: (1, 4)
s = 3
p = 2
No solution, impossible problem
I'd like to get this automagically.
I filled a table with the first few rows and columns and I noticed we get a diagonal matrix., since we cannot have a solution when s > p
Hope to have been clear.
I wait for your opinions.
Bye and thanx!