This file contains 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
# 二分木探索 Binary Search Tree | |
class Node | |
attr_accessor :val, :left, :right | |
def initialize(val) | |
@val = val | |
end | |
end | |
def insert(node, val) |
This file contains 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
$heap = [] | |
$size = 0 | |
# heap実装 | |
def push(x) | |
# ヒープが空ならRootに追加して抜ける | |
return $heap[0] = x if $heap.empty? | |
# 追加されたノードが収まるindex | |
i = $size += 1 |
This file contains 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
# input | |
$n = 4 | |
$m = 4 | |
$s = "abcd" | |
$t = "becd" | |
# 2つの文字列の、共通部分列の長さの最大値を求める | |
# 解 3 "bcd" | |
$dp = Array.new($n + 1, 0){ Array.new($m + 1, 0)} |
This file contains 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
# input | |
$n = 4 | |
$w = [2, 1, 3, 2] | |
$v = [3, 2, 4, 2] | |
$W = 5 | |
$dp = Array.new($n + 1, 0){ Array.new($W + 1, 0)} | |
# 重さ$wと価値$vの組み合わせの品物が$n個ある | |
# 重さの総和が$Wを超えないように選んだときの価値の総和の最大値を求める | |
# 動的計画法 Dynamic Programming |
This file contains 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
# input | |
$n = 4 | |
$w = [2, 1, 3, 2] | |
$v = [3, 2, 4, 2] | |
$W = 5 | |
$dp = Array.new($n + 1, -1){ Array.new($W + 1, -1)} | |
# 重さ$wと価値$vの組み合わせの品物が$n個ある | |
# 重さの総和が$Wを超えないように選んだときの価値の総和の最大値を求める |
This file contains 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
# input | |
$n = 4 | |
$w = [2, 1, 3, 2] | |
$v = [3, 2, 4, 2] | |
$W = 5 | |
# 重さ$wと価値$vの組み合わせの品物が$n個ある | |
# 重さの総和が$Wを超えないように選んだときの価値の総和の最大値を求める | |
def rec(i, j) |
This file contains 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
#input | |
$V = [1, 5, 10, 50, 100, 500] | |
# 1円玉3枚, 10円玉2枚... 500円玉2枚 | |
$C = [3, 2, 1, 3, 0, 2] | |
$A = 620 #620円支払う | |
# $A円を支払う最小の硬貨数を求める | |
def slove |
This file contains 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
# input | |
MAX_N, MAX_M = 100, 100 | |
$INF = 100_000_000 | |
str = <<"EOS" | |
#S.#.....# | |
#.....##.# | |
#.#.#..#..# | |
#..#..#### | |
####G##### |
This file contains 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
# input | |
$n = 4 | |
$a = [1, 2, 4, 7] | |
$k = 13 | |
# 配列aからいくつか選び、その和をちょうどkにすることが | |
# できるかを求める | |
def dfs(i, sum) | |
return sum == $k if i == $n |
This file contains 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
let scrollstep = 250 | |
let blacklists = ["*://gist.github.com/*", "*://github.com/*", "*://mail.google.com/*", "*://*.rakuten-bank.co.jp/*"] |