Created
December 8, 2014 07:58
-
-
Save yoshiokatsuneo/7f1d78d9c78b3fbdbc3e to your computer and use it in GitHub Desktop.
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
# 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