class Solution {
public:
int numSquares(int n) {
vector<int> f(n + 1);
for (int i = 1; i <= n; i++) {
int minn = INT_MAX;
for (int j = 1; j * j <= i; j++) {
minn = min(minn, f[i - j * j]); //上一次的 & 当前数可以找到一个新的更大的平方
}
f[i] = minn + 1;
}
return f[n];
}
};