LoginSignup
0
1

More than 5 years have passed since last update.

ツリーの中の数

Last updated at Posted at 2017-09-20

やるだけですね.とりあえずn<=10**15まで耐えられるっぽいです.

tyama_f06.rb
#!/usr/bin/env ruby
#http://nabetani.sakura.ne.jp/hena/ordf06numit/
#https://qiita.com/Nabetani/items/deda571c9451bd7d3175
STDOUT.sync=true

def dfs(n,t)
    return 1 if n==t
    return 0 if n<t
    $memo[n]||=[n/2-10,n*2/3].map{|e|
        e>0 ? dfs(e,t) : 0
    }.reduce(:+)
end

while gets
    $memo={}
    n,t=$_.split(',').map(&:to_i)
    p dfs(n,t)
end
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1