QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#168236 | #2481. Pickpockets | LaStataleBlue# | TL | 93ms | 5912kb | C++23 | 1.7kb | 2023-09-08 00:16:55 | 2023-09-08 00:16:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXT = 16, inf = 16'000'006;
int h,t,dp[MAXT][1<<MAXT],sumd[1<<MAXT],sumv[1<<MAXT],d[MAXT],v[MAXT];
vector<int> len;
int f(int pos,int mask){
if(pos==len.size())return 0;
int res = -inf;
for(int i=mask;i>0;i=((i-1)&mask)){
if(sumd[i]==len[pos]){
res = max(res, sumv[i] + f(pos+1,mask^i));
}
}
return res;
}
void solve(){
cin>>h>>t;
vector tmp(t+1,0);
for(int i=0;i<h;i++){
int c;
cin>>c;
if(c>t){
cout<<"0\n";
return;
}
for(int j=1;j<=c;j++){
tmp[j]++;
}
for(int j=c+1;j<=t;j++){
if(tmp[j]>0){
len.push_back(tmp[j]);
tmp[j]=0;
}
}
}
for(int j=1;j<=t;j++){
if(tmp[j]>0){
len.push_back(tmp[j]);
tmp[j]=0;
}
}
if(len.size()>t){
cout<<"0\n";
return;
}
for(int i=0;i<t;i++){
cin>>d[i]>>v[i];
}
for(int i=0;i<(1<<t);i++){
for(int j=0;j<t;j++){
if(i&(1<<j)){
sumd[i]+=d[j];
sumv[i]+=v[j];
}
}
}
for(int i=len.size();i>=0;i--){
for(int j=0;j<(1<<t);j++){
dp[i][j]=f(i,j);
}
}
if(dp[0][(1<<t)-1]<0)cout<<"0\n";
else cout<<dp[0][(1<<t)-1]<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3640kb
input:
2 2 1 2 1 5 2 5
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 0ms
memory: 5908kb
input:
2 2 1 2 2 5 1 5
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
3 4 2 1 2 3 2 1 1 1 2 1 3
output:
7
result:
ok single line: '7'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
1 5 2 1 2 1 5 1 3 1 5 1 3
output:
10
result:
ok single line: '10'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
1 5 1 1 2 1 1 1 2 1 5 1 2
output:
5
result:
ok single line: '5'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
1 7 0 1 5 1 5 1 5 1 2 1 5 1 3 1 6
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
3 6 2 1 1 2 1 3 5 2 3 3 3 2 4 3 3
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5652kb
input:
2 5 1 1 1 5 2 4 1 4 2 2 1 1
output:
9
result:
ok single line: '9'
Test #9:
score: 0
Accepted
time: 0ms
memory: 5620kb
input:
1 2 1 1 5 1 4
output:
5
result:
ok single line: '5'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 4 0 1 1 6 2 2 2 5 2 5
output:
6
result:
ok single line: '6'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
3 5 0 0 0 3 2 3 1 3 1 1 3 1 5
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
3 6 0 1 0 3 3 1 3 1 2 1 2 1 3 3 2
output:
3
result:
ok single line: '3'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
2 7 2 0 2 2 1 6 2 4 1 6 1 6 1 2 2 6
output:
12
result:
ok single line: '12'
Test #14:
score: 0
Accepted
time: 1ms
memory: 5712kb
input:
2 6 0 3 2 3 2 16 1 12 2 10 1 16 1 8
output:
36
result:
ok single line: '36'
Test #15:
score: 0
Accepted
time: 93ms
memory: 5860kb
input:
3 13 4 0 3 1 19 3 12 1 13 2 19 1 18 3 4 3 10 1 13 1 19 2 10 3 15 1 20 3 5
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
4 2 3 2 4 0 4 10 3 14
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Accepted
time: 1ms
memory: 5696kb
input:
4 6 3 1 3 1 4 9 4 18 1 15 3 15 2 6 1 19
output:
0
result:
ok single line: '0'
Test #18:
score: 0
Accepted
time: 24ms
memory: 4032kb
input:
3 14 3 0 1 3 16 3 7 3 9 3 11 3 15 3 15 2 16 1 1 2 18 3 16 3 13 3 11 1 4 3 4
output:
0
result:
ok single line: '0'
Test #19:
score: 0
Accepted
time: 2ms
memory: 5912kb
input:
2 9 3 1 1 18 1 15 1 15 1 4 2 17 1 4 2 1 1 15 2 16
output:
63
result:
ok single line: '63'
Test #20:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
1 9 2 1 5 1 11 1 20 1 10 1 10 1 11 1 9 1 8 1 19
output:
39
result:
ok single line: '39'
Test #21:
score: 0
Accepted
time: 1ms
memory: 5908kb
input:
4 7 1 0 0 2 4 15 4 18 2 8 2 2 2 6 3 11 3 11
output:
0
result:
ok single line: '0'
Test #22:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
2 2 2 3 2 6 1 1
output:
0
result:
ok single line: '0'
Test #23:
score: -100
Time Limit Exceeded
input:
1 15 4 1 2 1 12 1 7 1 5 1 13 1 10 1 7 1 5 1 1 1 18 1 9 1 5 1 17 1 9 1 6