当前位置:网站首页>Codeforces 1637 D. yet another minimization problem - Mathematics, DP
Codeforces 1637 D. yet another minimization problem - Mathematics, DP
2022-06-12 13:32:00 【Tianyi City*】
The question :
Give you a length of n Of a Array and b Array , You can choose one location at a time i, In exchange for a[i],b[i]. In the end, make ∑ i = 1 n ∑ j = i + 1 n ( a [ i ] + a [ j ] ) 2 + ∑ i = 1 n ∑ j = i + 1 n ( b [ i ] + b [ j ] ) 2 \sum\limits_{i=1}^{n}\sum\limits_{j=i+1}^{n}(a[i]+a[j])^2+\sum\limits_{i=1}^{n}\sum\limits_{j=i+1}^{n}(b[i]+b[j])^2 i=1∑nj=i+1∑n(a[i]+a[j])2+i=1∑nj=i+1∑n(b[i]+b[j])2 Minimum .
What is the minimum value .
Answer key :
This is a 1800? I can't even think of it …
It seems that the problem of this formula has not been encountered for some time , I didn't even think about that .
It's almost such a process , So at the end of the formula a and b We already know the sum of the squares of , So what we are looking for is the smallest of the last two items .
hypothesis a And for x, that b The sum of is the sum of all the numbers -x Chant . See, for all a Is it possible that
dp[i][j] It means No i When we count ,a And for j The possibility of
So there are two cases of state transition :
if(j>=a[i])dp[1-i%2][j]|=dp[i%2][j-a[i]];
if(j>=b[i])dp[1-i%2][j]|=dp[i%2][j-b[i]];
#include<bits/stdc++.h>
using namespace std;
const int N=105;
bool dp[2][N*N];
int a[N],b[N];
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n,ans=0,r=0,sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]),ans+=a[i]*a[i]*(n-2),sum+=a[i];
for(int i=1;i<=n;i++)scanf("%d",&b[i]),ans+=b[i]*b[i]*(n-2),sum+=b[i];
memset(dp[1],0,sizeof dp[1]);
dp[1][0]=1;
for(int i=1;i<=n;i++){
r+=max(a[i],b[i]);
memset(dp[1-i%2],0,sizeof dp[1-i%2]);
for(int j=r;j>=min(a[i],b[i]);j--){
if(j>=a[i])dp[1-i%2][j]|=dp[i%2][j-a[i]];
if(j>=b[i])dp[1-i%2][j]|=dp[i%2][j-b[i]];
}
}
int mi=1e9;
for(int i=0;i<=r;i++)
if(dp[1-n%2][i])
mi=min(mi,i*i+(sum-i)*(sum-i));
printf("%d\n",ans+mi);
}
return 0;
}
边栏推荐
- Getting started with NVIDIA Jetson nano Developer Kit
- Implementing pytorch style deep learning framework similartorch with numpy
- 5V升压到12.6V的锂电池充电IC芯片方案FS4062B
- Tensorrt, onnx to tensorrt in mmclas
- "Non" reliability of TCP
- 高通平台开发系列讲解(协议篇)QMI简单介绍及使用方法
- 【云原生 | Kubernetes篇】深入了解Ingress
- [cloud native | kubernetes] in depth understanding of deployment (VIII)
- Record some settings for visual studio 2019
- Symbolic constant, const qualifier
猜你喜欢

Realization of Joseph Ring with one-way ring linked list

简历 NFT 平台 TrustRecruit 加入章鱼网络成为候选应用链

智能垃圾桶语音芯片应用设计方案介绍,WT588F02B-8S

Volume mount and mirror creation

Chrome debugging tool

微信web开发者工具使用教程,web开发问题
![[EDA] chip layout design: VLSI layout design using electric](/img/a1/da0739070c940b36bc7a55d8eb2fe5.jpg)
[EDA] chip layout design: VLSI layout design using electric
![2061: [example 1.2] trapezoidal area](/img/83/79b73ca10615c852768aba8d2a5049.jpg)
2061: [example 1.2] trapezoidal area

Implementing pytorch style deep learning framework similartorch with numpy

Octopus network progress monthly report | may 1-May 31, 2022
随机推荐
Encryptor and client authenticate with each other
单向环形链表实现约瑟夫环
C language implementation of string and memory library functions
Scyther工具形式化分析Woo-Lam协议
403 you don't have permission to access this resource
1001:Hello,World
It is enough to read this article. Web Chinese development
import torch_ Geometric loads some common datasets
Implementing tensorflow deep learning framework similarflow with numpy
【云原生 | Kubernetes篇】深入了解Deployment(八)
Tensorrt, onnx to tensorrt in mmclas
Symbolic constant, const qualifier
Informatics Olympiad all in one 1000: introductory test questions
Actual combat | realizing monocular camera ranging by skillfully using pose solution
Redis message queue repeated consumption
Hudi key generation
成功定级腾讯T3-2,万字解析
static 和 extern 关键字详解
Script import CDN link prompt net:: err_ FILE_ NOT_ Found problem
m1 pod install pod lint 失败解决方案