Skip to content

Instantly share code, notes, and snippets.

@yoshiokatsuneo
Created December 8, 2014 07:58
Show Gist options
  • Save yoshiokatsuneo/7f1d78d9c78b3fbdbc3e to your computer and use it in GitHub Desktop.
Save yoshiokatsuneo/7f1d78d9c78b3fbdbc3e to your computer and use it in GitHub Desktop.
# POH 3 // greedy
@m = gets.to_i
@n = gets.to_i
@companies = []
@n.times{
q, r = gets.split.map(&:to_i)
@companies.push([q, r])
}
def calc(i, engineers, cost)
if i == @n
if engineers >= @m
return cost
else
return 999999999999
end
end
ret1 = calc(i+1, engineers, cost)
ret2 = calc(i+1, engineers+@companies[i][0], cost+@companies[i][1])
return [ret1, ret2].min
end
puts calc(0, 0, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment