诸位硕佬们帮帮忙!60分求解

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

遐思神游 @ 2018-04-16 18:24:41

```cpp

include <iostream>

include <cstring>

using namespace std; int w[200005][4],v[200005][4]; int an=0; int m,n; int dp[200005]; int main(){ memset(w,0,sizeof(w)); memset(v,0,sizeof(v)); memset(dp,0,sizeof(dp)); cin>>n>>m; int i,j,k,l; int v0,p,q; for(i=1;i<=m;i++){ cin>>v0>>p>>q; if(q==0){ an++; w[an][1]=v0; v[an][1]=v0p; } else{ w[q][0]++; w[q][w[q][0]+1]=v0; v[q][0]++; v[q][v[q][0]+1]=v0p; } } dp[0]=0; int k1,k2,k3,k4,k5; for(i=1;i<=an;i++){ for(j=n;j>=w[i][1];j--){ k3=0;k4=0;k5=0; k1=dp[j]; k2=dp[j-w[i][1]]+v[i][1];

        if(j>=w[i][1]+w[i][2])
            k3=dp[j-w[i][1]-w[i][2]] +v[i][1]+v[i][2];

        if(j>=w[i][1]+w[i][3])
            k4=dp[j-w[i][1]-w[i][3]] +v[i][1]+v[i][3];

        if(j>=w[i][1]+w[i][2]+w[i][3])
            k5=dp[j-w[i][1]-w[i][2]-w[i][3]] +v[i][1]+v[i][2]+v[i][3];

                 dp[j]=max(k1,max(k2,max(k3,max(k4,k5))));
    }
}
cout<<dp[n];
return 0;

}


by 遐思神游 @ 2018-04-16 18:27:38

好吧 插入代码不知道为什么插成这样233 各位硕佬帮帮忙 代码如下:

#include <iostream>
#include <cstring>
using namespace std;
int w[200005][4],v[200005][4];
int an=0;
int m,n;
int dp[200005];
int main(){
    memset(w,0,sizeof(w));
    memset(v,0,sizeof(v));
    memset(dp,0,sizeof(dp));
    cin>>n>>m;
    int i,j,k,l;
    int v0,p,q;
    for(i=1;i<=m;i++){
        cin>>v0>>p>>q;
        if(q==0){
            an++;
            w[an][1]=v0;
            v[an][1]=v0*p;
        }
        else{
            w[q][0]++;
            w[q][w[q][0]+1]=v0;
            v[q][0]++;
            v[q][v[q][0]+1]=v0*p;
        }
    }
    dp[0]=0;
    int k1,k2,k3,k4,k5;
    for(i=1;i<=an;i++){
        for(j=n;j>=w[i][1];j--){
            k3=0;k4=0;k5=0;
            k1=dp[j];
            k2=dp[j-w[i][1]]+v[i][1];

            if(j>=w[i][1]+w[i][2])
                k3=dp[j-w[i][1]-w[i][2]] +v[i][1]+v[i][2];

            if(j>=w[i][1]+w[i][3])
                k4=dp[j-w[i][1]-w[i][3]]+v[i][1]+v[i][3];

            if(j>=w[i][1]+w[i][2]+w[i][3])
                k5=dp[j-w[i][1]-w[i][2]-w[i][3]] +v[i][1]+v[i][2]+v[i][3];

            dp[j]=max(k1,max(k2,max(k3,max(k4,k5))));
        }
    }
    cout<<dp[n];
    return 0;
}

by YLWang @ 2018-04-16 18:29:31

应该没问题


by YLWang @ 2018-04-16 18:29:39

是WA吗


|