小lagi @ 2020-01-04 20:20:55
//力气与剩余力气比,若第一个大则dfs,否则最多为/
//能够着的总数
#include<stdio.h>
int apple1[5000],apple2[5000],k=0,m=0,max=0,s;
void DFS(int index,int sum,int cnt)
{
if(index==k||sum>=s)
{
if(sum==s)
if(cnt>max)
max=cnt;
return;
}
DFS(index+1,sum+apple2[index],cnt+1);
DFS(index+1,sum,cnt);
}
int main()
{
int n,a,b,i,j,c,d,Sum=0;
scanf("%d%d%d%d",&n,&s,&a,&b);
for(i=0;i<=n-1;i++)
{
scanf("%d%d",&c,&d);
if(c<=a+b)
{
apple1[k++]=c;
apple2[m++]=d;
}
}
for(j=0;j<=m-1;j++)
Sum+=apple2[j];
if(Sum>=s)
max=m-1;
else
DFS(0,0,0);
printf("%d",max);
return 0;
}```