洛谷P2430

还是很容易能看出来是01背包

#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
#define fi(i,a,b) for(int i = a; i <= b; ++i)
#define fr(i,a,b) for(int i = a; i >= b; --i)
#define x first
#define y second
#define sz(x) ((int)(x).size())
#define pb push_back
using pii = pair<int,int>;
//#define DEBUG
int dp[5005];
int w[5005];
int v[5005];
int t[5005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    int k = m / n;
    int p,q;
    cin >> p >> q;
    fi(i,1,q){
        cin >> t[i];
        t[i] *= k;
    }
    fi(i,1,p){
        cin >> w[i] >> v[i];
    }
    int num;
    cin >> num;
    fi(i,1,p){
        fr(j,num,t[w[i]]){
            dp[j] = max(dp[j - t[w[i]]] + v[i],dp[j]);
        }
    }
    cout << dp[num] << endl;
#ifdef DEBUG
    //freopen(D:\in.txt,r,stdin);
#endif
    return 0;
}
posted @ 2022-02-22 16:44  Sun-Wind  阅读(27)  评论(0编辑  收藏  举报