QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#873305 | #7739. Knapsack | makeran | Compile Error | / | / | C++20 | 979b | 2025-01-26 11:42:20 | 2025-01-26 11:42:27 |
Judging History
answer
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
struct node {
int w,v;
} obj[5010];
int dp[5010][1001000];
int f[5010];
bool cmp(node a,node b) {
if(a.w==b.w) return a.v>b.v;
return a.w<b.w;
}
bool cmp2(int a,int b){
return a>b;
}
signed main() {
int n,w,k;
// freopen("knapsack8.in","r",stdin);
cin>>n>>w>>k;
for(int i=1; i<=n; i++) {
cin>>obj[i].w>>obj[i].v;
}
sort(obj+1,obj+1+n,cmp);
for(int i=1; i<=n; i++) {
for(int j=0; j<=w; j++) {
if(j-obj[i].w>=0)
dp[i][j]=max(dp[i-1][j],dp[i-1][j-obj[i].w]+obj[i].v);
}
}
int res=0;
int temp=0;
int idx=0;
for(int i=n;i>=0;i--){
temp=dp[i][w];
idx++;
f[idx]=obj[i+1].v;
for(int j=idx;j>1;j--){
if(f[j]>f[j-1]) swap(f[j],f[j-1]);
else break;
}
for(int j=1;j<=min(idx,k);j++){
temp+=f[j];
}
res=max(res,temp);
}
cout<<res;
return 0;
}
// f[1]=0;
/*
5 13 2
5 16
5 28
7 44
8 15
8 41
*/
詳細信息
/tmp/ccxTnrvb.o: in function `main': answer.code:(.text.startup+0x59): relocation truncated to fit: R_X86_64_PC32 against symbol `obj' defined in .bss section in /tmp/ccxTnrvb.o answer.code:(.text.startup+0xb2): relocation truncated to fit: R_X86_64_PC32 against symbol `obj' defined in .bss section in /tmp/ccxTnrvb.o answer.code:(.text.startup+0xc0): relocation truncated to fit: R_X86_64_PC32 against symbol `obj' defined in .bss section in /tmp/ccxTnrvb.o answer.code:(.text.startup+0xf0): relocation truncated to fit: R_X86_64_PC32 against symbol `obj' defined in .bss section in /tmp/ccxTnrvb.o answer.code:(.text.startup+0x139): relocation truncated to fit: R_X86_64_PC32 against symbol `obj' defined in .bss section in /tmp/ccxTnrvb.o answer.code:(.text.startup+0x14e): relocation truncated to fit: R_X86_64_PC32 against symbol `obj' defined in .bss section in /tmp/ccxTnrvb.o answer.code:(.text.startup+0x1a6): relocation truncated to fit: R_X86_64_PC32 against symbol `obj' defined in .bss section in /tmp/ccxTnrvb.o answer.code:(.text.startup+0x21a): relocation truncated to fit: R_X86_64_PC32 against symbol `obj' defined in .bss section in /tmp/ccxTnrvb.o answer.code:(.text.startup+0x26b): relocation truncated to fit: R_X86_64_PC32 against symbol `obj' defined in .bss section in /tmp/ccxTnrvb.o answer.code:(.text.startup+0x44d): relocation truncated to fit: R_X86_64_PC32 against symbol `obj' defined in .bss section in /tmp/ccxTnrvb.o answer.code:(.text.startup+0x465): additional relocation overflows omitted from the output collect2: error: ld returned 1 exit status