#1450429

Solution for 0030: Sum of Integers by iwamot

Source Code Status Test Cases
    Policy: public     Reviewed: 108    
00.02 sec    6100 KB    17 lines     272 bytes    2015-07-18 21:24
def dfs(a, n, s)
  return (a.inject(:+) == s) ? 1 : 0 if a.size == n

  ans = 0
  (a.empty? ? 0 : a.max + 1).upto(9) do |i|
    ans += dfs(a + [i], n, s)
  end
  ans
end

while true
  n, s = gets.split(' ').map(&:to_i)
  break if n == 0 && s == 0
  puts dfs([], n, s)
end


Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 1/1 Ruby CPU: 00.02 sec Memory: 6100 KB Length: 272 B 2015-07-18 21:24 2015-07-18 21:24
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 00.02 sec 6100 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags