@memo = {} def f(d, x) if d == 1 @memo[[d, x]] = 1 return 1 end if d == 2 @memo[[d, x]] = x + 1 return x + 1 end if d == 3 @memo[[d, x]] = (x + 2) * (x + 1) / 2 return @memo[[d, x]] end count = 0 (0..x).each do |i| if !@memo.key?([d - 1, i]) @memo[[d - 1, i]] = f(d - 1, i) end count += @memo[[d - 1, i]] end @memo[[d, x]] = count return count end q = gets.chomp.to_i q.times do d, x, t = gets.chomp.split(' ') d = d.to_i x = x.to_i t = t.to_i if f(d, x) <= t # p @memo[[d, x]] puts "AC" else # p @memo[[d, x]] puts "ZETUBOU" end end