01背包+输出所选背包
来源:互联网 发布:云计算市场规模 编辑:程序博客网 时间:2024/06/05 20:16
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=100;
int dp[maxn][maxn];
int value[maxn];
int weight[maxn];
int x[maxn];
int main(){
int n,c;
freopen("f.txt","r",stdin);
while(~scanf("%d%d",&n,&c)){
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++){
scanf("%d",&value[i]);
}
for(int i=1;i<=n;i++){
scanf("%d",&weight[i]);
}
int i,j;
for(i=1;i<=n;i++){
for(j=weight[i];j<=c;j++){
dp[i][j]=max(dp[i-1][j],dp[i-1][j-weight[i]]+value[i]);
}
}
printf("Optimal value is\n%d\n",dp[n][c]);
j=c;
for(i=n;i>=0;i--){
if(dp[i][j]>dp[i-1][j]){
x[i]=1;
j-=weight[i];
}else{
x[i]=0;
}
}
for(i=1;i<=n;i++){
if(i==1) printf("%d",x[i]);
else printf(" %d",x[i]);
}
}
}
- 01背包+输出所选背包
- 01背包路径输出
- 【背包专题】01背包
- 01背包,完全背包
- 01背包 完全背包
- 01背包/完全背包
- 01背包,完全背包
- 背包问题---01背包
- 背包入门--01背包
- 【背包专题】01背包
- 01背包,完全背包
- UVa 624 CD (01背包路径输出)
- 输出01背包内物品的程序
- CD+uva+01背包(输出方案)
- UVA 624 CD 01背包 输出解
- UVA 624 CD(01背包输出)
- uva624 CD 01背包+输出路径
- UVA 264 CD (01背包+输出路径)
- NYOJ 839 合并
- yii2中自定义验证规则rules
- 练习二 1017 非常可乐
- 对于jQuery中$(xxx:not(xxx))的一个范例
- colorAccent,colorPrimary,colorPrimaryDark……来这里你就明白了
- 01背包+输出所选背包
- Java语言基础1
- 关于链式表达式
- Git操作
- poj 2533 poj3903 poj1836 最长上升子序列 LIS
- 这些小工具让你的 Android 开发更高效(下)
- Leetcode—— trapping-rain-water
- [leetcode] 8. String to Integer (atoi)
- YTU 2335: 0-1背包问题