QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#358068 | #7793. 雷同 | LastFlame | 0 | 11ms | 115128kb | C++14 | 2.2kb | 2024-03-19 16:57:28 | 2024-03-19 16:57:29 |
Judging History
answer
/*
考虑建模,将合并操作当作新建一个节点,作为合并的两摞书的父节点,相当于合并后的一摞书
考虑这样建出的二叉树可以唯一的确定一种合并方案,考虑这种合并方案的贡献怎么计算
考虑每个叶子结点代表最开始的一本书,重量值的贡献就是每本书的 W 乘上该节点的深度
考虑磨损值怎么计算,考虑进行长链剖分,因为对于一个节点,其磨损值一定是取决于其子树中最深的深度,因为合并时我们肯定选小磨损值贡献
考虑进行长链剖分后,考虑每条链只会做 2^(n-1)-1 的贡献
我们考虑设计状态 f(i,j) 表示已经钦定了 i 个节点为叶子,当前层还有 j 个节点不是叶子,n<i+j 的状态是不合法的,可以减掉
考虑转移,可以结束当前层的决策,f(i,2*j)=f(i,j)+sigma(w(k))(k>i)
可以钦定一个叶子,f(i+1,j-1)=f(i,j)+lowbit(j)/2
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mn=5555;
int T,n,w[mn];
int n2[30],lb[mn];
ll sumw[mn],dp[mn][mn];
ll ans;
int read(){
int x=0,w=1;
char ch=getchar();
while(ch<'0' || ch>'9'){
if(ch=='-') w=-1;
ch=getchar();
}
while(ch>='0' && ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*w;
}
void ready(){
n2[0]=1;
for(int i=1;i<=20;i++) n2[i]=n2[i-1]<<1;
for(int i=0;i<=13;i++){
for(int j=n2[i];j<=1e4;j+=n2[i+1]) lb[j]=n2[i];
}
return;
}
int main(){
T=read();
ready();
while(T--){
n=read();
for(int i=1;i<=n;i++) w[i]=read();
sort(w+1,w+n+1);
sumw[0]=0;
for(int i=1;i<=n;i++) sumw[i]=sumw[i-1]+w[i];
for(int i=0;i<=n;i++) for(int j=0;i+j<=n;j++) dp[i][j]=1e18;
dp[0][1]=0;
for(int i=0;i<n;i++){
for(int j=1;i+j<=n;j++){
// cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;
if((j<<1)<=n) dp[i][j<<1]=min(dp[i][j<<1],dp[i][j]+sumw[n-i]);
dp[i+1][j-1]=min(dp[i+1][j-1],dp[i][j]+lb[j-1]);
}
}
ans=dp[n][0]-(n-1);
cout<<ans<<endl;
}
return 0;
}
/*
5
6
1 1 4 5 1 4
6
10 10 40 50 10 40
5
1000000000 1000000000 1000000000 1000000000 1000000000
6
1 3 15 105 945 27455185
6
1 2 3 4 5 6
1
4
1 1 1 1
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3704kb
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:
84 101 1979 2034324
result:
wrong answer 1st words differ - expected: '86', found: '84'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
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: 11ms
memory: 115128kb
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:
92698 37354249907
result:
wrong answer 1st words differ - expected: '96493', found: '92698'
Subtask #7:
score: 0
Skipped
Dependency #5:
0%