申请添加Hack数据

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

wfirstzhang @ 2024-07-08 14:16:33

输入:

100 3
1000 5 3
10 5 3
50 2 0

输出:

150

如果没考虑到情况“只选附件 2”也能 AC,但是这组数据会输出 100

错误代码:

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

#define TRACE 1
#define tcout TRACE && cout

#define IN(o) insert(o)

#define fi first
#define se second

#define int long long

#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const int INF = 0x3f3f3f3f3f3f3f3f;

const int P = 998244353;

const int N = 1e6 + 10;

int n, m;

int f[N], wa[N], va[N];

vector<pair<int, int>> b[N];

signed main()
{
    cin >> n >> m;
    for(int i=1; i<=m; i++)
    {
        int v, p, q;
        cin >> v >> p >> q;
        if(q == 0)
        {
            wa[i] = v;
            va[i] = p;
        }
        else
        {
            b[q].push_back({v, p});
        }
    }
    for(int i=1; i<=m; i++)
    {
        for(int j=n; j>=wa[i]; j--)
        {
            f[j] = max(f[j], f[j-wa[i]] + (wa[i] * va[i]));
            if(b[i].size() == 0) continue;
            if(j-wa[i]-b[i][0].fi >= 0) f[j] = max(f[j], f[j-wa[i]-b[i][0].fi] + (wa[i] * va[i]) + (b[i][0].fi * b[i][0].se));
            if(b[i].size() < 2) continue;
            if(j-wa[i]-b[i][0].fi-b[i][1].fi >= 0) f[j] = max(f[j], f[j-wa[i]-b[i][0].fi-b[i][1].fi] + (wa[i] * va[i]) + (b[i][0].fi * b[i][0].se) + (b[i][1].fi * b[i][1].se));
        }
    }
    int res = 0;
    for(int i=1; i<=n; i++) res = max(res, f[i]);
    cout << res;
    return 0;
}

by wfirstzhang @ 2024-07-08 14:26:04

@Maxmilite


by wfirstzhang @ 2024-07-08 14:29:59

@离散小波变换°


by Maxmilite @ 2024-07-08 19:16:12

@wfirstzhang added, thx.


by _fwTransform_ @ 2024-07-24 07:01:11

@wfirstzhang 没听懂,为什么能只选附件2?附件不是必须带着主件?


by wfirstzhang @ 2024-07-24 08:18:51

@ReturnOrContinue 我的意思是附件只选 10 5 3 的。主件当然选。


by _fwTransform_ @ 2024-07-24 08:29:07

@wfirstzhang 不食镉钔这波hack加的我直接暴毙()

感觉和之前的hack差不多但也是安心地亖了


by wfirstzhang @ 2024-07-24 09:05:36

@ReturnOrContinue 你 WA 的不是我加的。


by _fwTransform_ @ 2024-07-24 12:14:48

@wfirstzhang 但是我过了啊()


by SwethessPotion @ 2024-07-27 15:39:33

@wfirstzhang 雀食是错误代码,代码里全是 wa[i] (手动doge


|