题解 | #最小邮票数#动态规划
最小邮票数
https://www.nowcoder.com/practice/83800ae3292b4256b7349ded5f178dd1
#include<iostream> #include <vector> #include <climits> using namespace std; int main() { int m, n; while (cin >> m >> n) { vector<int> dp(m + 1, INT_MAX); dp[0] = 0; for (int i = 0; i < n; i++) { int value; cin >> value; for (int j = m; j >= value; j--) { if (dp[j - value] != INT_MAX && dp[j - value] + 1 < dp[j]) { dp[j] = dp[j - value] + 1; } } } cout << (dp[m] == INT_MAX ? 0 : dp[m]) << endl; } return 0; }