Created
December 8, 2014 08:11
-
-
Save yoshiokatsuneo/57ed6981c9e9f316b36f 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, bit | |
@m = gets.to_i | |
@n = gets.to_i | |
@companies = [] | |
@n.times{ | |
q, r = gets.split.map(&:to_i) | |
@companies.push([q, r]) | |
} | |
mincost = 99999999999 | |
(0..2**@n).each{|i| | |
engineers = 0 | |
cost = 0 | |
(0...@n).each{|j| | |
if (i & (1<<j) != 0) then | |
engineers += @companies[j][0] | |
cost += @companies[j][1] | |
end | |
} | |
if engineers >= @m | |
mincost = [mincost, cost].min | |
end | |
} | |
puts mincost | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment