QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#257505 | #7793. 雷同 | zhouhuanyi | 5 | 0ms | 3788kb | C++14 | 1.1kb | 2023-11-19 09:29:43 | 2023-11-19 09:29:43 |
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 80
#define M 7
using namespace std;
const long long inf=(long long)(1e18);
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
bool cmp(int x,int y)
{
return x>y;
}
int lowbit(int x)
{
return x&(-x);
}
int t,n,w[N+1];
long long S[N+1],dp[N+1][N+1][M+1],ans;
int main()
{
t=read();
while (t--)
{
n=read(),ans=inf;
for (int i=1;i<=n;++i) w[i]=read();
sort(w+1,w+n+1,cmp);
for (int i=1;i<=n;++i) S[i]=S[i-1]+w[i];
for (int i=1;i<=n;++i)
for (int j=i;j<=n;++j)
for (int k=0;k<=M;++k)
dp[i][j][k]=inf;
for (int i=1;i<=n;++i) dp[i][i][0]=0;
for (int i=n;i>=1;--i)
for (int j=i;j<=n;++j)
for (int k=i;k<=j-1;++k)
for (int t=0;t<=M-1;++t)
for (int s=0;s<=M-1;++s)
dp[i][j][max(t,s)+1]=min(dp[i][j][max(t,s)+1],dp[i][k][t]+dp[k+1][j][s]+S[j]-S[i-1]+t);
for (int i=1;i<=M;++i) ans=min(ans,dp[1][n][i]);
printf("%lld\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 3788kb
input:
4 6 1 3 5 7 9 11 6 2 4 6 8 10 12 6 100 1000 100 10 100 10 2 114514 1919810
output:
86 103 1981 2034324
result:
ok 4 tokens
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 3752kb
input:
5 12 2 4 3 2 2 3 4 2 3 2 2 1 12 3 3 3 2 3 2 3 2 1 1 2 4 12 6 2 2 2 5 4 6 1 2 8 8 6 12 1 4 2 2 1 6 7 2 4 1 7 5 12 11 1 2 6 16 16 15 8 8 16 6 12
output:
112 108 182 145 399
result:
wrong answer 1st words differ - expected: '114', found: '112'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Wrong Answer
Test #39:
score: 0
Wrong Answer
time: 0ms
memory: 3760kb
input:
2 2500 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3...
output:
15 15 15 15
result:
wrong answer 1st words differ - expected: '96493', found: '15'
Subtask #7:
score: 0
Skipped
Dependency #5:
0%