Featured image of post [模板]背包

[模板]背包

01背包

1
2
3
for (int i = 1; i <= n; i++)
    for (int v = m; v >= w[i]; v--)
      dp[v] = max(dp[v - w[i]] + c[i], dp[v]);

完全背包

1
2
3
 for (int i = 1; i <= n; i++)
        for (int j = w[i]; j <= m; j++)
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
Licensed under CC BY-NC-SA 4.0
本站已安全运行
总访问量 次 | 访客 人 | 共 27 篇文章
Built with Hugo
主题 StackJimmy 设计