제출 #1163635

#제출 시각아이디문제언어결과실행 시간메모리
1163635ramalzaherKnapsack (NOI18_knapsack)C++20
37 / 100
1097 ms38720 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 10000000;
int dp[N], w[N], v[N];
void solve()
{
    int n, m;
    cin >> m >> n;
    int z = 0;
    for (int i = 0; i < n; i++)
    {
        int k,x,y;
        cin >> x >> y >> k;
        while(k > 0)
        {
            v[z]=x;w[z]=y;
            z++;
            k--;
        }
    }
    dp[0] = 0;
    for (int i = 0; i < z; i++)
    {
        //cout << v[i]<< " " << w[i] <<"\n";
            for (int j = m; j > 0; j--)
        {
            if (j - w[i] < 0)
            {
                continue;
            }
            dp[j] = max(dp[j], (dp[j - w[i]] + v[i]));
        }
    }
    cout << dp[m] << endl;
}
main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen(".in", "r", stdin);
    //     freopen(".out", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tt = 1;
    // cin >> tt;
    while (tt--)
    {
        solve();
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...