"""
http://elementsofprogramminginterviews.com/pdf/epi-light-1.4.8.pdf
17.1 Count the number of score combinations
In an American football game, a play can lead to 2 points (safety), 3 points (field
goal), or 7 points (touchdown). Given the final score of a game, we want to compute
how many di erent combinations of 2, 3, and 7 point plays could make up this score.
For example, if W = f2; 3; 7g, four combinations of plays yield a score of 12:
6 safeties (2 6 = 12),
3 safeties and 2 field goals (2 3 + 3 2 = 12),
1 safety, 1 field goal and 1 touchdown (2 1 + 3 1 + 7 1 = 12), and
4 field goals (3 4 = 12).
Problem 17.1 : You have an aggregate score s and W which specifies the points that
can be scored in an individual play. Howwould you find the number of combinations
of plays that result in an aggregate score of s? How would you compute the number
of distinct sequences of individual plays that result in a score of s?
"""
def count_combinations(k, score_ways):
combinations = [0] * (k+1)
combinations[0] = 1
for score in score_ways:
print "score=", score
for j in range(score, k+1):
combinations[j] += combinations[j - score]
return combinations[k]
"""
hint:
https://andrew.neitsch.ca/publications/m496pres1.nb.pdf
http://stackoverflow.com/questions/1106929/find-all-combinations-of-coins-when-given-some-dollar-value
"""
Blog Archive
-
▼
2014
(190)
-
▼
August
(23)
- 十道海量数据处理面试题与十个方法大总结 - 结构之法 算法之道 - 博客频道 - CSDN.NET
- Backtracking | Set 2 (Rat in a Maze) - GeeksforGeeks
- Amazon Jobs | Push the Envelope with Amazon’s Spee...
- [leetcode]Longest Consecutive Sequence @ Python - ...
- AIDasr - 博客园
- Find all combinations of coins when given some dol...
- [leetcode]Edit Distance @ Python - 南郭子綦 - 博客园
- Google APAC 2015 University Graduates Test
- My Own Notes: LeetCode (Python): Flatten Binary Tr...
- LeetCode题解整理版(二) | Coding 4 Fun
- Binary Tree Preorder Inorder Postorder Traversal ...
- Binary Tree Level Order Traversal II | LeetCode OJ
- LeetCode — Binary Tree Preorder Traversal(C++ Java...
- 前女友因为我没进Google而和我分手 (转载) - 未名空间(mitbbs.com)
- [Mitbbs]FB的intern和准备的经历 - - 博客频道 - CSDN.NET
- Google coding Style Guide
- LeetCode OJ --问题与解答 前言
- Lexi's Leetcode solutions
- LeetCode 分类
- Can Mobile Technologies and Big Data Improve Healt...
- 喀什葛尔胡杨歌词
- Study: Noise-Induced Hearing Loss Alters Brain Res...
- How to Focus
-
▼
August
(23)
Friday, August 22, 2014
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment