本文共 365 字,大约阅读时间需要 1 分钟。
完全背包为什么要取到M,可以取到2*M嘛,这题需要整取,对于不能整取的背包容量,dp[k]=INF,以及dp[j-water[i].weight]=INF时,dp[j]也不需要更新。如果不整取的话,后面无法得知背包是否装满了,只知道,背包容量为m时,所花的最小消耗是多少,但是此时背包可能没装满。
#includeusing namespace std;typedef long long ll;const int INF=0x3f3f3f3f;const int N=2e4+10;struct Node { int w,v;}wat[1010];ll dp[N],weight[N];bool cmp(const Node &a,const Node &b){ return a.w
转载地址:http://xruen.baihongyu.com/