这里写目录标题
- 139. 单词拆分
 - 多重背包问题
 - 背包问题总结
 
139. 单词拆分
单词就是物品,字符串s就是背包
 1.dp[0]背包啥也不要用装,true。
 2. for循环,顺序很重要,所以先背包再物品
 如果求组合数就是外层for循环遍历物品,内层for遍历背包。
 如果求排列数就是外层for遍历背包,内层for循环遍历物品。
 3.递归:
 要么装包或者不装
添加链接描述
class Solution {
    public boolean wordBreak(String s, List<String> wordDict) {
        int len = s.length();
     boolean[] dp = new boolean[len+1];
     dp[0] = true;
     for(int i=1;i<=len;i++){ //背包
        for(String word : wordDict){
            int n = word.length();
            if(i>=n&&word.equals(s.substring(i-n,i))){
                dp[i] =  dp[i] ||dp[i-n];
            }
        }
     }
     return dp[len];
    }
}
 
多重背包问题
背包问题总结
把这五部都搞透了,算是对动规来理解深入了。
确定dp数组(dp table)以及下标的含义
 确定递推公式
 dp数组如何初始化
 确定遍历顺序
 举例推导dp数组

 2.遍历顺序
 一维:第二层的背包是从大到小
 
注意for循环分别表示的含义
 



















