problem:https://leetcode.com/problems/perfect-squares
数字类dp。查找当前数字减去一个平方数对应的最小拆分次数。
class Solution { public: int numSquares(int n) { vector<int> dp(n + 1, INT_MAX); dp[0] = 0; for(int i = 1;i <= n; i++) { for(int j = 1;j * j <= i; j++) { dp[i] = min(dp[i], dp[i - j * j] + 1); } } return dp[n]; } };