youngyangyang04 / leetcode-master-comment

用来做评论区
0 stars 0 forks source link

[Vssue]周总结/20210204动规周末总结.md #162

Open youngyangyang04 opened 4 months ago

youngyangyang04 commented 4 months ago

https://www.programmercarl.com/%E5%91%A8%E6%80%BB%E7%BB%93/20210204%E5%8A%A8%E8%A7%84%E5%91%A8%E6%9C%AB%E6%80%BB%E7%BB%93.html

lkh2022 commented 3 months ago

这里可以int j=ii,下面不用if判断 // 版本二 class Solution { public: int numSquares(int n) { vector dp(n + 1, INT_MAX); dp[0] = 0; for (int i = 1; i i <= n; i++) { // 遍历物品 for (int j = 1; j <= n; j++) { // 遍历背包 if (j - i i >= 0) { dp[j] = min(dp[j - i i] + 1, dp[j]); } } } return dp[n]; } };

JIE-yx commented 1 month ago

半囫囵吞枣式地按顺序刷了20道dp的题目,然后从头开始跟着作者整理了一下笔记,再看了一下这些问题,理解更加深刻了。也更能感受到作者在刷题顺序上下的良苦用心!👍