This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 最長共通部分列問題 | |
| ## http://rubyfiddle.com/riddles/10ea3 | |
| s = "abcd" | |
| t = "becd" | |
| n = s.length | |
| m = t.length | |
| dp = Array.new(n+1,0).map{Array.new(m+1,0)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 個数制限なしナップサック問題 | |
| ## http://rubyfiddle.com/riddles/9eb7a | |
| n = 3 | |
| w = [3,4,2] | |
| v = [4,5,3] | |
| W = 7 | |
| dp = Array.new(W+1,0) | |
| i=j=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 三角形 | |
| ## http://rubyfiddle.com/riddles/6bad3 | |
| a = [2, 3, 4, 5, 10] | |
| ans = 0 | |
| a.combination(3){|v,j,k| | |
| if k < (v+j) | |
| if ans < (v+j+k) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 2進数変換と比較 | |
| ## http://rubyfiddle.com/riddles/17c56 | |
| day = Time.local(1966,07,13) | |
| ans = [] | |
| def day2bin(date) | |
| return date.strftime("%Y%m%d").to_i.to_s(2) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 個数制限つき部分和問題 | |
| ## http://rubyfiddle.com/riddles/cffe6 | |
| n=3 | |
| a=[3,5,8] | |
| m=[3,2,2] | |
| K=17 | |
| dp = Array.new(K+1,-1) | |
| dp[0] = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 部分和問題 | |
| ## http://rubyfiddle.com/riddles/2083e | |
| # 配列の大きさ。rubyだと簡単に求められるので使う機会がない。 | |
| n = 4 | |
| # カンマ区切りで[ ]の中の値を変えてみてね! | |
| # ex. [1, 2, 3, 4, 8, 10, 12] | |
| a = [ 1, 2 , 4, 7] | |
| # 求める和。好きな数字に変えてみよう!半角数字でお願いします。 | |
| k = 13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 区間スケジューリング問題 | |
| ## http://rubyfiddle.com/riddles/da7c6 | |
| n = 5 | |
| s = [1, 2, 4, 6, 8] | |
| t = [3, 5, 7, 9, 10] | |
| a = [] | |
| ans = 0 | |
| last = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Saruman's Army (POJ 3069) | |
| ## http://rubyfiddle.com/riddles/b5dfa | |
| R=10 | |
| x = [1, 7, 15, 20, 30, 50] | |
| N = x.size | |
| ans = [] | |
| i = j = 0 | |
| while x[1] != nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 重複組合せ | |
| ## http://rubyfiddle.com/riddles/aba0f | |
| n = 3 | |
| m = 3 | |
| a = [1, 2, 3] | |
| M = 10000 | |
| dp = Array.new(n+1,0).map{Array.new(m+1,0)} | |
| (n+1).times{|i| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## ナップサック問題その2 | |
| ## http://rubyfiddle.com/riddles/5c02c | |
| n = 4 | |
| w = [2,1,3,2] | |
| v = [3,2,4,2] | |
| W = 5 | |
| res =0 | |
| INF = 1000000 |
NewerOlder