Created
December 7, 2013 14:05
-
-
Save inage/7841763 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
| ## 分割数 | |
| ## http://rubyfiddle.com/riddles/b8293 | |
| n = 4 | |
| m = 3 | |
| M = 10000 | |
| res = 0 | |
| (1..m).each{|i| | |
| Array(1..n).repeated_combination(i){|a| | |
| res += 1 if a.inject(:+) == n | |
| } | |
| } | |
| puts res % M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment