Skip to content

Instantly share code, notes, and snippets.

@yoshiokatsuneo
Created December 8, 2014 08:59
Show Gist options
  • Save yoshiokatsuneo/dbf8fef0c15ed21953a0 to your computer and use it in GitHub Desktop.
Save yoshiokatsuneo/dbf8fef0c15ed21953a0 to your computer and use it in GitHub Desktop.
# POH3 // DP
m = gets.to_i
n = gets.to_i
dp = Array.new(m+1, 9999999999999)
dp[0] = 0
n.times{
q, r = gets.split.map(&:to_i)
m.downto(0).each{|i|
q2 = [i+q, m].min
dp[q2] = [dp[q2], dp[i]+r].min
}
}
puts dp[m]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment