lintylong @ 2023-10-06 20:12:10
#include <bits/stdc++.h>
using namespace std;
int n,s,a,b;
int x[10010],y[10010];
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;
for(int i=1;i<=n;i++)
{
cin>>x[i]>>y[i];
}
cout<<dfs(1,s);
return 0;
}
WA第2个测试点,TLE第3、4个测试点。
by dingzj2022 @ 2023-10-06 20:31:42
d第一眼简单,下一眼默默退出
by xzq4121 @ 2023-10-06 20:44:42
#include <bits/stdc++.h>
using namespace std;
int a[5010],b[5010],l[5010];
int main(){
int c,d,e,f,g,h,i=110,j,k=0;
cin>>c>>d>>e>>f;
h=e+f;
for(g=1;g<=c;g++){
cin>>a[g]>>b[g];
if(a[g]>h) l[g]=1;
}
while(d>0){
for(g=1;g<=c;g++){
if(l[g]==0){
if(b[g]<i){
i=b[g];
j=g;
}
}
}
l[j]=1;
if(d>=b[j]){
d=d-b[j];
k++;
}
else break;
i=110;
}
cout<<k;
return 0;
}
by lintylong @ 2023-10-07 19:04:29
@xzq4121 谢谢,已明白,已关注。