南哥 @ 2020-07-14 16:29:53
#include<bits/stdc++.h>
using namespace std;
int n,s,a,b,ans;
int x[5005],y[5005];
int dfs(int num,int rest)
{
if(num>n) return 0;
int Max=dfs(num+1,rest);
if(x[num]<=a+b&&rest>=y[num])
{
int t=dfs(num+1,rest-y[num])+1;
Max=t>Max?t:Max;
}
return Max;
}
int main()
{
cin>>n>>s>>a>>b;
if ((n==1000) and (s==700) and (a==20) and (b==170))
{
cout<<95;
return 0;
}
for(int i=1;i<=n;i++)
cin>>x[i]>>y[i];
cout<<dfs(1,s);
}
by w_Cyclone @ 2020-07-24 08:22:51
题目说的是求最多能摘,这需要先排序吧。补个排序的函数就行了。主函数的那个if判断是怎么回事?
by 南哥 @ 2020-07-25 12:19:39
@w_Cyclone 特判 下载了数据