背包问题
来源:互联网 发布:淘宝严查刷单时间 编辑:程序博客网 时间:2024/05/17 09:04
int KnapsackProblem(int *pweight, int *pvalue, int n, int w)
{
int *ptbl=malloc(sizeof(int)*(w+1));
memset(ptbl, 0, sizeof(int)*(w+1));
for(int i=0; i<n; ++i)
for(int j=w; j>=pweight[i]; --j)
if(ptbl[j]<pvalue[i]+ptbl[j-pweight[i]])
ptbl[j]=pvalue[i]+ptbl[j-pweight[i]];
w=ptbl[w];
free(ptbl);
return w;
}
{
int *ptbl=malloc(sizeof(int)*(w+1));
memset(ptbl, 0, sizeof(int)*(w+1));
for(int i=0; i<n; ++i)
for(int j=w; j>=pweight[i]; --j)
if(ptbl[j]<pvalue[i]+ptbl[j-pweight[i]])
ptbl[j]=pvalue[i]+ptbl[j-pweight[i]];
w=ptbl[w];
free(ptbl);
return w;
}
0 0
- 【无限背包】背包问题
- 背包问题---01背包
- 背包问题--部分背包
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- 背包问题
- redhat samba
- 浏览器2014官方下载
- UIScrollView--滚动视图
- 4Sum
- Linux内存管理机制学习-1
- 背包问题
- hadoop 1.2.1 安装
- Hive修改表语句
- 面向对象--设计模式概览
- 一个关于webservice的Axis问题 Processing file deploy.wsdd Exception: deploy.wsdd (系统找不到指定的文件。)
- 英语学习平台
- FFmpeg浅尝辄止(四)——音频的解码和编码
- Letter Combinations of a Phone Number
- 20140608 learn by Ruby on Rails Tutorial