30 pts 求调

P1064 [NOIP2006 提高组] 金明的预算方案

_Dolphin_ @ 2024-03-05 19:01:48

#include<bits/stdc++.h>
#define afor(x,y,z) for(int x=y;x<=z;x++)
#define bfor(x,y,z) for(int x=y;x>=z;x--)
#define cfor(x,y) for(int x=head[y];x;x=nxt[x])
using namespace std;
typedef long long ll;
typedef const int cint;
cint N=3300;
int n,m,mw[N],mv[N],cnt[N],aw[N][3],av[N][3],f[N];
int main() {
    scanf("%d%d",&n,&m);
    afor(i,1,m) {
        int v,p,q;
        scanf("%d%d%d",&v,&p,&q);
        if(!q) mw[i]=v,mv[i]=v*p;
        else cnt[q]++,aw[q][cnt[q]]=v,av[q][cnt[q]]=v*p;
    }
    afor(i,1,m) bfor(j,n,mw[i]) {
        f[j]=max(f[j],f[j-mw[i]]+mv[i]);
        if(j>=mw[i]+aw[i][1])
            f[j]=max(f[j],f[j-mw[i]-aw[i][1]]+mv[i]+av[i][1]);
        if(j>=mw[i]+aw[i][2])
            f[j]=max(f[j],f[j-mw[i]-aw[i][2]]+mv[i]+av[i][2]);
        if(j>=mw[i]+aw[i][1]+aw[i][2])
            f[j]=max(f[j],f[j-mw[i]-aw[i][1]-aw[i][2]]+mv[i]+av[i][1]+av[i][2]);
    }
    printf("%d",f[n]);
    return 0;
}

by _Dolphin_ @ 2024-03-05 19:15:29

已过


by _Dolphin_ @ 2024-03-05 19:15:47

开得不够大


|