Daniel000 @ 2019-10-02 14:58:09
#include <iostream>
using namespace std;
int main()
{
int n,a,b,s,xi[300],yi[120];
int i,t,ans=0;
cin>>n>>s;
cin>>a>>b;
for(i=0;i<n;i++)
{
cin>>xi[i]>>yi[i];
}
for(i=0;i<n-1;i++)//冒泡排序
{
for(int j=i+1;j<n;j++)
{
if(yi[i]>yi[j])
{
t = yi[j];
yi[j] = yi[i];
yi[i] = t;
t = xi[j];
xi[j] = xi[i];
xi[i] = t;
}
}
}
i=0;
while(s>0&&i<n)
{
if(a+b>=xi[i]&&yi[i]<=s)//够得到,体力足够
{
s=s-yi[i];
ans++;
}
i++;
}
cout<<ans;
return 0;
}
下载次数上限了,我找不出错误,求助大佬。
by 北极星欧拉56 @ 2019-10-02 15:10:43
可以当背包DP来做
#include<bits/stdc++.h>
using namespace std;
struct catchapple
{
int hi;
int force;
};
catchapple a[10001];
int n,c,b,x,i,j;
int f[10001];
int main()
{
cin>>n>>x>>c>>b;
for(i=1;i<=n;i++)
cin>>a[i].hi>>a[i].force;
for(i=1;i<=n;i++)
for(j=x;j>=a[i].force;j--)
if(c+b>=a[i].hi)
f[j]=max(f[j],f[j-a[i].force]+1);
cout<<f[x];
return 0;
}