90分,救命!!!
查看原帖
90分,救命!!!
397712
dingyibo楼主2022/12/11 12:06
#include <bits/stdc++.h>
#define MAX_T 8343000
#define MAX_M 10001
using namespace std;
unsigned long long t, m;
unsigned long long dp[2][MAX_T];
struct Herbs
{
    unsigned long long time;
    unsigned long long price;
};
Herbs herbs[MAX_M];
unsigned long long GatherHerbs( )
{
    unsigned long long i, j;

    for(i=0;i<=m;++i)
    {
        for(j=0;j<=t;++j)
        {
            if(i == 0 || j == 0)
                dp[i%2][j] = 0;
            else if(herbs[i-1].time > j)
                dp[i%2][j] = dp[(i-1)%2][j];
            else
                dp[i%2][j] = max( herbs[i-1].price+dp[i%2][j-herbs[i-1].time], dp[(i-1)%2][j]);
        }
    }

    return dp[m%2][t];
}

int main()
{
    ios::sync_with_stdio(false);
    unsigned long long i;

    cin>>t>>m;

    for(i=0;i<m;++i)
        cin>>herbs[i].time>>herbs[i].price;

    cout<<GatherHerbs( )<<endl;
    return 0;
}

最后一个点MLE,求助!!!

2022/12/11 12:06
加载中...