C++ 动态规划问题 要点: dp[j] = min(dp[j], dp[j - arr[i]] + 1); dp[0] = 0;
int dp[aim + 1];
dp[0] = 0;
for (int i = 1; i <= aim; ++i) dp[i] = INT_MAX-1;
for (int i = 0; i < arr.size(); ++i) {
for (int j = arr[i]; j <= aim; ++j)
dp[j] = min(dp[j], dp[j - arr[i]] + 1);
}
if (dp[aim] == INT_MAX-1) return -1;
return dp[aim];