ZOJ 2639 01背包
来源:互联网 发布:mac桌面添加天气 编辑:程序博客网 时间:2024/05/16 18:37
求第K优解
#include<iostream>
#include<cstdio>#include<cstring>
using namespace std;
int main()
{
int t,n,v,k,K;
int f[1010][35];
int value[110],volum[110];
int a[35],b[35];
int x,y,z;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&v,&K);
for(int i=1;i<=n;i++)
cin>>value[i];
for(int j=1;j<=n;j++)
cin>>volum[j];
memset(f,0,sizeof(f));
for(int i=1;i<=n;i++)
for(int j=v;j>=volum[i];j--)
{
for(k=1;k<=K;k++ )
{
a[k]=f[j-volum[i]][k]+value[i];
b[k]=f[j][k];
}
a[k]=b[k]=-1;
x=y=z=1;
while(z<=k&&(a[x]!=-1||b[y]!=-1)) //忘了里面的括号,导致测试用例都一样,但是就是A不了
{
if(a[x]>b[y])
f[j][z]=a[x++];
else
f[j][z]=b[y++];
if(f[j][z]!=f[j][z-1])
z++;
}
}
cout<<f[v][K]<<endl;
}
return 0;
}
- ZOJ 2639 01背包
- zoj 3956 01背包
- ZOJ 3258 Wistone and Owenwater 01背包+完全背包
- Cookie Choice+ZOJ+01背包之终级背包
- zoj月赛 3689 01背包
- ZOJ 1163 The Staircases / 01背包
- ZOJ 1163 The Staircases(01背包)
- zoj 3812 We Need Medicine(01背包)
- ZOJ 3956 Course Selection System 01背包
- Zoj 3956 Course Selection System【01背包】
- ZOJ 3956 Course Selection System 01背包
- ZOJ-3956 Course Selection System,01背包!
- ZOJ-3956 Course Selection System(01背包)
- ZOJ 0-1背包
- zoj 3623(完全背包)
- zoj 3689 简单背包
- zoj 3164 各种背包
- ZOJ 2972(背包dp)
- 数组Array进行原型prototype扩展后带来的for in遍历问题
- 磁盘修复
- 计算尺寸
- maven-bundle-plugin
- weka-分类算法
- ZOJ 2639 01背包
- JQueryEasyUI学习笔记(八)datagrid
- C#更改gif图片大小后仍然保持动画效果
- 俞敏洪在同济大学的演讲
- 设计模式推演——一切从需求分析开始
- Java_集合_Collections工具类
- Linux下安装jdk1.6
- 1777年的今天,卡尔·弗里德里希·高斯诞生
- C++ Boost 库文档索引