Created
February 12, 2018 19:43
-
-
Save erikseulean/2a17689b2d778c6bc8db3830f2863b07 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ''' | |
| given a final score in a certain sport, get all the possible scores during | |
| the game. the scoring points are given ahead | |
| ''' | |
| from copy import copy | |
| def get_scores(points, result): | |
| dp = [0 for _ in range(result + 1)] | |
| dp[0] = 1 | |
| for point in points: | |
| for value in range(point, result + 1): | |
| dp[value] = dp[value] + dp[value - point] | |
| return dp | |
| def get_subsets(points, dp, current, subset, allsets): | |
| if current == 0: | |
| allsets.append(subset) | |
| return | |
| for point in points: | |
| if current >= point and dp[current - point] != 0: | |
| subset.append(point) | |
| get_subsets(points, dp, current - point, copy(subset), allsets) | |
| subset = subset[:-1] | |
| allsets = [] | |
| scores = get_scores([2,3], 10) | |
| get_subsets([2,3], scores, 10, [], allsets) | |
| print(allsets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment