이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x)*(x)
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ldb;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef unsigned long long ull;
int s,n,dp[2001][2001],res;
vector<pii> w[2001];
int main(){
FAST;
cin>>s>>n;
for(int i=1;i<=n;++i){
int V,W,K;
cin>>V>>W>>K;
w[W].push_back(mp(V,K));
}
for(int i=1;i<=s;++i){
//cout<<i<<'\n';
sort(w[i].begin(),w[i].end(),greater<pii>());
for(int j=1;j<=s;++j){
int idx=0,cnt=0,Sw=0,Sval=0;
vector<pii> a(w[i]);
dp[i][j]=dp[i-1][j];
while(cnt<j/i&&idx<w[i].size()){
++cnt;
Sw+=i;
Sval+=a[idx].fi;
dp[i][j]=max(dp[i][j],dp[i-1][j-Sw]+Sval);
a[idx].se--;
if(!a[idx].se) ++idx;
}
//cout<<j<<' '<<dp[i][j]<<'\n';
res=max(res,dp[i][j]);
}
}
cout<<res;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'int main()':
knapsack.cpp:34:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | while(cnt<j/i&&idx<w[i].size()){
| ~~~^~~~~~~~~~~~
# | 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... |