40分请大佬帮助

P1478 陶陶摘苹果(升级版)

somethingfornothing @ 2018-09-01 23:06:14


#include<cstdio>
#include<iostream>
using namespace std;
int a[5001],b[5001],f[5001][5001];
int main()
{
    int n,s,x,y,ans=0;
    cin>>n>>s>>x>>y;
    int h=x+y;
    int k=s;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=s;j>=b[i];j--)
        {
            if(h>a[i])
            {
                f[i][j]=max(f[i-1][j],f[i-1][j-b[i]]+1);
            }
            else 
            {
                f[i][j]=f[i-1][j];
            }
        }
    }
    cout<<f[n][s];
}```

by 孤独を見守る @ 2018-09-01 23:08:23

#include<iostream>
using namespace std;
int n,s,a,b,ans=0,t1,t2;
int xi[5010],yi[5010];
int main() {
    cin>>n>>s>>a>>b;
    a+=b;
    for(int i=1; i<=n; i++) {
        cin>>xi[i]>>yi[i];
    }
    for(int i=1; i<n; i++) {
        for(int j=i+1; j<=n; j++) {
            if(yi[i]>yi[j]) {
                t1=xi[i],t2=yi[i];
                xi[i]=xi[j],yi[i]=yi[j];
                xi[j]=t1,yi[j]=t2;
            }
        }
    }
    for(int i=1; i<=n; i++) {
        if(xi[i]<=a&&yi[i]<=s) {
            ans++;
            s-=yi[i];
        }
    }
    cout<<ans;
    return 0;
}

@Mr_chen


by 孤独を見守る @ 2018-09-01 23:10:55

@Mr_chen


by somethingfornothing @ 2018-09-01 23:11:52

dp有吗


by somethingfornothing @ 2018-09-01 23:12:04

@AC无敌机


by 孤独を見守る @ 2018-09-01 23:13:24

@Mr_chen 用dp太麻烦,看看标签啊QAQ


by 孤独を見守る @ 2018-09-01 23:22:24

ok


|