9 1 + 8 2 + 7 3 + 6 4 + 5 1 + 2 + 6 1 + 3 + 5 2 + 3 + 4
Above shows a total of eight number of ways to express the number 9 as the sum of distinct positive integer in ascending order.
What is the total number of ways to express the number 58 as the sum of distinct positive integer in ascending order?
Bonus : Define f ( n ) as the total number of ways to express the positive integer n as the sum of distinct positive integers in ascending order. Prove that there exist a polynomial of minimum degree 2 n ( n + 1 ) such that you can find f ( 1 ) , f ( 2 ) , … , f ( n ) . Construct this polynomial.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Great! That's a simple recursive way to find the sum. For this problem, it doesn't seem like dynamic programming would help, and we just have to find the value on a case by case basis.
Yay! Thankyouuu
Python 2.7:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Algorithm used: Breadth-First Search
Yay! Now solve the bonus question!
Log in to reply
The bonus question (as stated) does not make sense to me. Given any n values, I can always find a polynomial of degree n − 1 that takes on those values.
Log in to reply
I guess the problem asks for a polynomial of degree 2 n ( n + 1 ) ? This is typically harder than a degree n − 1 polynomial.
Log in to reply
@Sualeh Asif – I'm confused by what you mean. n − 1 < 2 n ( n + 1 so it is more restrictive. At the most, I will add ( x − 1 ) ( x − 2 ) ( x − 3 ) … ( x − 2 n ( n + 1 ) to my polynomial to get the degree to match.
Log in to reply
@Calvin Lin – Would my bonus question make sense if I remove the words "minimum degree"?
Here's DP solution for those who wants optimization:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
Problem Loading...
Note Loading...
Set Loading...
Simple recursion using Java: