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/5deb1 | |
| # 品物の大きさ | |
| $w = [2, 1, 3, 2] | |
| # 品物の価値 | |
| $v = [3, 2, 4, 2] | |
| N = $w.size | |
| # ナップサックの容量 | |
| W=5 |
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
| ## Lake Counting(POJ No.2386) | |
| ## http://rubyfiddle.com/riddles/2f66f | |
| N = 10 | |
| M = 12 | |
| $field = [] | |
| #庭の状態 | |
| data = <<"EOS" |
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/2031d | |
| a = [4,2,3,1,5] | |
| n = a.size | |
| dp = Array.new(n+1,nil) | |
| res =0 | |
| n.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
| ## くじ引き | |
| ## http://rubyfiddle.com/riddles/c4cf7 | |
| n = 3 | |
| m = 9 | |
| k = [ 1 , 3 , 5] | |
| ans = "" | |
| k.repeated_combination(4){|a,b,c| |
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/b8293 | |
| n = 4 | |
| m = 3 | |
| M = 10000 | |
| res = 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
| ## Best Cow Line (POJ 3617) | |
| ## http://rubyfiddle.com/riddles/f878f | |
| s = "ACDBCB" | |
| n = s.length #文字の長さ。"ACDBCB"の場合は6。 | |
| t = "" | |
| i=0 | |
| loop do | |
| break if s.size == 1 |
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/ade12 | |
| #各硬貨の価値 | |
| value = [1, 5, 10, 50, 100, 500] | |
| #必要な枚数 | |
| ans = 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/d4bdf | |
| $field = [] | |
| INF=100000 | |
| start = [] | |
| $goal = [] | |
| ans = INF |
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
| ## Fence Repair (POJ 3253) | |
| ## http://rubyfiddle.com/riddles/62daf | |
| l=[8,5,8] | |
| n=l.size | |
| while n > 0 | |
| ans =0 | |
| mii1 = 0 | |
| mii2 = 1 |
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/e301e | |
| n = 50 | |
| ans = 0 | |
| def fib(n) | |
| if n < 2 | |
| return n |