이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
const int mn=2000+5;
const int mod=1e9+7;
struct ITEM{
int v,w,k;
bool operator < (const ITEM& o) const {
return v<o.v;
}
} item[mn];
int dp[mn];
vector<int> v[mn];
signed main(){
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int s,n;
cin>>s>>n;
for (int i=1;i<=n;i++){
cin>>item[i].v>>item[i].w>>item[i].k;
}
sort(item+1,item+n+1);
memset(dp,-0x3f,sizeof(dp));
dp[0]=0;
for (int i=n;i>=1;i--){
while (item[i].k&&v[item[i].w].size()<s/item[i].w){
item[i].k--;
v[item[i].w].pb(item[i].v);
}
}
for (int i=1;i<=s;i++){
for (int j=0;j<v[i].size();j++){
for (int k=s;k>=i;k--){
dp[k]=max(dp[k],dp[k-i]+v[i][j]);
}
}
}
int ans=0;
for (int i=1;i<=s;i++)ans=max(ans,dp[i]);
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'int main()':
knapsack.cpp:32:42: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
32 | while (item[i].k&&v[item[i].w].size()<s/item[i].w){
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
knapsack.cpp:38:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int j=0;j<v[i].size();j++){
| ~^~~~~~~~~~~~
# | 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... |