hdu2639---Bone Collector II(01背包升华)

Problem Description
The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup" competition,you must have seem this title.If you haven't seen it before,it doesn't matter,I will give you a link:

Today we are not desiring the maximum value of bones,but the K-th maximum value of the bones.NOTICE that,we considerate two ways that get the same value of bones are the same.That means,it will be a strictly decreasing sequence from the 1st maximum , 2nd maximum .. to the K-th maximum.

If the total number of different values is less than K,just ouput 0.

Input
The first line contain a integer T , the number of cases.
Followed by T cases , each case three lines , the first line contain two integer N , V, K(N <= 100 , V <= 1000 , K <= 30)representing the number of bones and the volume of his bag and the K we need. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.

Output
One integer per line representing the K-th maximum of the total value (this number will be less than 2 31).

Sample Input
`35 10 21 2 3 4 55 4 3 2 15 10 121 2 3 4 55 4 3 2 15 10 161 2 3 4 55 4 3 2 1`

Sample Output
```1220代码实现：
#include

#include

using namespace std;int num[110];int value[110];int dp[1010][35];int d1[1010];int d2[1010];int main(){
int t,n,m,k,x,y,z,p;
cin>>t;
while(t--)
{
memset(dp,0,sizeof(dp));
memset(d1,0,sizeof(d1));
memset(d2,0,sizeof(d2));
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
cin>>value[i];
for(int i=1;i<=n;i++)
cin>>num[i];
for(int i=1;i<=n;i++)
{
for(int j=m;j>=num[i];j--)
{
for(p=1;p<=k;p++)
{
d1[p]=dp[j][p];
d2[p]=dp[j-num[i]][p]+value[i];
}
d1[p]=d2[p]=-1;
x=y=z=1;
while((d1[x]!=-1||d2[y]!=-1)&&z<=k)
{
if(d1[x]>d2[y])
{
dp[j][z]=d1[x];
x++;
}
else
{
dp[j][z]=d2[y];
y++;
}
if(dp[j][z-1]!=dp[j][z])
z++;
}
}
}
cout<

<

}
return 0;}

```

#### 最新留言

[***.249.68.14]2022年05月23日 01时25分01秒

## 关于作者

喝酒易醉，品茶养心，人生如梦，品茶悟道，何以解忧？唯有杜康！
-- 愿君每日到此一游！

## 最新文章

synchronized 不是万能，错误加锁 2019-08-03 02:38:22

Thread 和 Runnable 区别？ 2019-08-03 02:38:20
Mybatis 2019-08-03 02:38:20

Unix和Linux有什么区别？ 2019-08-03 02:38:16
【Python】之海龟图形化程序 2019-08-03 02:38:15

Redis持久化 2019-08-03 02:38:15