变成60分了,依然求助:(

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

ARTI001 @ 2024-01-19 16:49:32


#include<iostream>
#include<cstdio>
using namespace std;

int n,m;
int mv[65][3],mul[65][3];
int v,p,q;
int dp[65][32005];
int top[65];

int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>v>>p>>q;
        if(q==0)//主件 
        {
            mv[i][0]=v;
            mul[i][0]=v*p;//cout<<" "<<mul[i][0]<<endl;
        }
        else//附件 
        {
            mv[q][++top[q]]=v;
            mul[q][top[q]]=v*p;
        }
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=mv[i][0];j<=n;j++)
        {
            dp[i][j]=dp[i-1][j];

            if(mv[i][0]!=0)
            {
                if(j>=mv[i][0])
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-mv[i][0]]+mul[i][0]);

                if(j>=mv[i][0]+mv[i][1]&&mv[i][1]!=0)
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-mv[i][1]-mv[i][0]]+mul[i][1]+mul[i][0]);

                if(j>=mv[i][0]+mv[i][2]&&mv[i][2]!=0)
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-mv[i][2]-mv[i][0]]+mul[i][2]+mul[i][0]);

                if(j>=mv[i][0]+mv[i][1]+mv[i][2]&&mv[i][1]!=0&&mv[i][2]!=0)
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-mv[i][2]-mv[i][1]-mv[i][0]]+mul[i][2]+mul[i][1]+mul[i][0]); //printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
            }
        }
    }
    cout<<dp[m][n];
    return 0;
}

by ilibilib @ 2024-01-19 17:22:10

帮你下了份数据

in

2000 10
500 1 0
400 4 0
300 5 1
400 5 1
200 5 0
500 4 5
400 4 0
320 2 0
410 3 0
400 3 5

out

7430

by ARTI001 @ 2024-01-19 19:40:17

@ilibilib 谢谢啦


by ARTI001 @ 2024-01-19 23:03:59

把for循环的int j=mv[i][0];j<=n;j++中的mv[i][0]改成0之后莫名其妙多了十分……


by ilibilib @ 2024-01-20 22:10:37

@ARTI001 帮你看了看,max的不用和dp[i-1][j]比,和dp[i][j]比就行啦。可以ac


#include<iostream>
#include<cstdio>
using namespace std;

int n,m;
int mv[65][3],mul[65][3];
int v,p,q;
int dp[65][32005];
int top[65];

int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>v>>p>>q;
        if(q==0)//?? 
        {
            mv[i][0]=v;
            mul[i][0]=v*p;//cout<<" "<<mul[i][0]<<endl;
        }
        else//?? 
        {
            mv[q][++top[q]]=v;
            mul[q][top[q]]=v*p;
        }
    }
    for(int i=1;i<=m;i++)
    {
        for(int j=0;j<=n;j++)
        {
            dp[i][j]=dp[i-1][j];

            if(j>=mv[i][0])
            dp[i][j]=max(dp[i][j],dp[i-1][j-mv[i][0]]+mul[i][0]);

            if(j>=mv[i][0]+mv[i][1]&&mv[i][1]!=0)
            dp[i][j]=max(dp[i][j],dp[i-1][j-mv[i][1]-mv[i][0]]+mul[i][1]+mul[i][0]);

            if(j>=mv[i][0]+mv[i][2]&&mv[i][2]!=0)
            dp[i][j]=max(dp[i][j],dp[i-1][j-mv[i][2]-mv[i][0]]+mul[i][2]+mul[i][0]);

            if(j>=mv[i][0]+mv[i][1]+mv[i][2]&&mv[i][1]!=0&&mv[i][2]!=0)
            dp[i][j]=max(dp[i][j],dp[i-1][j-mv[i][2]-mv[i][1]-mv[i][0]]+mul[i][2]+mul[i][1]+mul[i][0]);//printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
        }
    }
    cout<<dp[m][n];
    return 0;
}

by ARTI001 @ 2024-01-21 12:59:40

@ilibilib 非常感谢!!(我的第一道绿题:D


|