Leetcode 279. 完全平方数 动态规划 完全背包问题
原题链接:Leetcode 279. 完全平方数
class Solution {
public:int numSquares(int n) {vector<int> dp(n + 1, 0);for (int i = 1; i <= n; i++) {int tmp = INT_MAX;for (int j = 1; j * j <= i; j++) {tmp = min(tmp, dp[i - j * j]);}dp[i] = tmp + 1;}return dp[n];}
};