#include <iostream>
#include <cstdio>
using namespace std;
int maxx = 0;
int a[25];
int b[25];
int n,k;
bool c[25];
int sum = 0;
int weight = 0;
int w;
void dfs(int l,int kk)
{
if(l==k)
{
if(sum>maxx&&weight<=w) maxx = sum;
return ;
}
if(kk==n) return ;
if(weight+b[kk]<=w)
{
sum += a[kk];
weight += b[kk];
dfs(l+1,kk+1);
sum -= a[kk];
weight -= b[kk];
}
dfs(l,kk+1);
}
void init()
{
int test;
cin>>test;
while(test--)
{
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i]>>b[i];
cin>>w;
sum = 0;maxx=0;
weight = 0;
dfs(0,0);
cout<<maxx<<endl;
}
}
int main()
{
init();
return 0;
}
hdu 2660
最新推荐文章于 2020-01-13 13:49:23 发布