0-1背包问题
来源:互联网 发布:jdbc连接两个数据库 编辑:程序博客网 时间:2024/06/05 21:51
有n个物品。第i个物品的体积为Vi,重量为Wi。选一些物品装到一个容量为C的背包,使得背包内物品在总体积不超过C的前提下重量尽量大。1<=n<=100,
1<=Vi<=C<=1000,1<=Wi<=10^6。
#include <iostream>#include <math.h>using namespace std;void fun(int V[], int W[], int n, int C){ int d[101][1001]; for (int i = 0; i <= C; i++) { d[n][i] = 0; } for (int i = n-1; i >= 0 ; i--) { for (int j = 0; j <= C; j++) { if (j >= V[i]) { d[i][j] = max(d[i+1][j], d[i+1][j-V[i]]+W[i]); } else { d[i][j] = d[i+1][j]; } } } cout << "result " << d[0][C] << endl;}int main(int argc, char *argv[]){ int V[3] = {1, 6, 3}; int W[3] = {1, 2, 3}; fun(V, W, 3, 7); return 0; }
0 0
- 背包问题(0-1背包、完全背包、多重背包)详解
- 背包问题和0-1背包问题
- 背包问题和0-1背包问题
- 背包问题系列--"0-1背包问题"
- 背包笔记-含0/1背包问题、完全背包问题、多重背包问题、二维背包问题、分组背包问题
- 【背包问题】背包问题之0-1背包、完全背包、多重背包
- 0-1背包问题
- 0/1背包问题
- 0,1背包问题
- 0-1背包问题
- 0/1背包问题
- 0-1背包问题
- // 0-1背包问题
- 0/1背包问题
- 0-1背包问题
- 0-1背包问题
- 0-1背包问题
- 0/1背包问题
- hdu 2157:How many ways??
- CF 390D:Inna and Sweet Matrix
- 大量时移、回看出错
- poj 3070:Fibonacci
- hdu 1233:还是畅通工程
- 0-1背包问题
- hdu 1879:继续畅通工程
- Eclipse使用技巧
- hdu 2544:最短路
- hdu 1874:畅通工程续
- hdu 2066:一个人的旅行
- 【四圣龙神录的编程教室】第15章、来制作凹梦的弹幕吧
- centos 中文乱码
- hdu 1317:XYZZY