震惊,蒟蒻耗费毕生功力想出的做法竟完全爆炸!

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

铁锤 @ 2019-08-13 16:55:37

RT,只A了两个点,求助!

#include<cstdio>
#include<algorithm>
using namespace std;
int n,m;
int cnt;
int val[70][4],w[70][4],tot[70],num[70];
int dp[70][32100];
int main() {
    int v,p,q;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) {
        scanf("%d%d%d",&v,&p,&q);
        if(q==0) {
            cnt++;
            num[i]=cnt;
            val[cnt][++tot[cnt]]=v;
            w[cnt][tot[cnt]]=p*v;
        }
        else {
            val[num[q]][++tot[num[q]]]=v;
            w[num[q]][tot[num[q]]]=p*v;
        }
    }
    for(int i=1;i<=cnt;i++) {
        if(tot[i]==2) {
            for(int j=(val[i][1]+val[i][2]);j<=n;j++) {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-val[i][1]-val[i][2]]+w[i][1]+w[i][2]);
            }
        }
        if(tot[i]==3) {
            for(int j=(val[i][1]+val[i][2]);j<=n;j++) {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-val[i][1]-val[i][2]]+w[i][1]+w[i][2]);
            }
            for(int j=(val[i][1]+val[i][3]);j<=n;j++) {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-val[i][1]-val[i][3]]+w[i][1]+w[i][3]);
            }
            for(int j=(val[i][1]+val[i][2]+val[i][3]);j<=n;j++) {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-val[i][1]-val[i][2]-val[i][3]]+w[i][1]+w[i][2]+w[i][3]);
            }
        }
        for(int j=val[i][1];j<=n;j++) {
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-val[i][1]]+w[i][1]);
        }
    }
    printf("%d",dp[cnt][n]);
    return 0;
}

by Knight_Master @ 2019-08-13 19:27:56

放心,我只A了7个点(表示一波同病相怜)


by 铁锤 @ 2019-08-13 19:30:54

嘤嘤嘤


by 铁锤 @ 2019-08-13 19:31:14

@36589157org (窝真是太菜了)


by Knight_Master @ 2019-08-13 20:12:13

@铁锤 那我这题量还不如去撞墙


|