# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
673701 | asteilind | Knapsack (NOI18_knapsack) | C++17 | 1081 ms | 344 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <set>
#include <numeric>
#include <bitset>
#include <climits>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define MOD 1000000007
using namespace std;
void setIO(string name = "") { // name is nonempty for USACO file I/O
ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output
if(name.length()){
freopen((name+".in").c_str(), "r", stdin); // see Input & Output
freopen((name+".out").c_str(), "w", stdout);
}
}
void solve()
{
ll s,n; cin >> s >> n;
vector<ll> price(n),weight(n),count(n);
forn(i,n) cin >> price[i] >> weight[i] >> count[i];
vector<ll> dp(s+1,-1);
dp[0] = 0;
ll res = 0;
for (ll a=0 ; n>a ; a++)
{
for (ll j = 0 ; count[a] > j ; j++)
{
for (ll i=s ; i >= 0; i--)
{
if (dp[i] != -1)
{
if (i+weight[a] > s) continue;
dp[i+weight[a]] = max(dp[i+weight[a]],dp[i]+price[a]);
res = max(res,dp[i+weight[a]]);
}
}
}
}
cout << res << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
setIO();
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |