-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#! /usr/bin/python | ||
# filename: 76.py | ||
|
||
''' | ||
how many different ways can one hundred be written as a sum of positive | ||
integers, at least 2 | ||
this problem is like coin changing problem31 | ||
dynamic programming | ||
need to look it more carefully from this on | ||
''' | ||
|
||
|
||
def main(): | ||
|
||
target = 100 | ||
ns = range(1, 100) | ||
ways = [1] + [0]*target | ||
|
||
for n in ns: | ||
for i in range(n, target+1): | ||
ways[i] += ways[i-n] | ||
|
||
print ways[target] | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |