Skip to content

Instantly share code, notes, and snippets.

@inage
Created December 7, 2013 14:07
Show Gist options
  • Select an option

  • Save inage/7841938 to your computer and use it in GitHub Desktop.

Select an option

Save inage/7841938 to your computer and use it in GitHub Desktop.
最長増加部分列問題
## 最長増加部分列問題
## http://rubyfiddle.com/riddles/2031d
a = [4,2,3,1,5]
n = a.size
dp = Array.new(n+1,nil)
res =0
n.times{|i|
dp[i]= 1
j=0
while j < i
if a[j] < a[i]
dp[i] = [dp[i],dp[j]+1].max
end
j += 1
end
res = [res,dp[i]].max
}
puts res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment