@memo = {} def f(d, x) if x == 1 @memo[[d, x]] = d return @memo[[d, x]] end 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 if !@memo.key?([d - 1, x]) @memo[[d - 1, x]] = f(d - 1, x) end if !@memo.key?([d, x - 1]) @memo[[d, x - 1]] = f(d, x - 1) end @memo[[d, x]] = @memo[[d - 1, x]] + @memo[[d, x - 1]] return @memo[[d, x]] 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