当前位置:网站首页>Minimize maximum
Minimize maximum
2022-06-11 05:21:00 【Food can be very delicious】
Very interesting topic
Title Description
Include a n The sequence of positive integers is divided into m Consecutive subsequences ( Each positive integer happens to belong to a sequence ). Set the first i The sum of the numbers of the sequences is S(i), Your task is to make all S(i) The maximum value of is as small as possible .
For example, the sequence 1 2 3 2 5 4 Divide into 3 The optimal scheme of the sequences is 1 2 3 | 2 5 | 4, among S(1)、S(2)、S(3) Respectively 6、7、4, The maximum is 7;
If you divide it into 1 2 | 3 2 | 5 4, Then the maximum value is 9, It's not as good as just now .n<=10^6, The sum of all numbers does not exceed 10 ^ 9.
Ideas
“ The maximum value shall be as small as possible ” Is a very common optimization goal . Let's consider a new problem : Can the input sequence be divided into m Consecutive subsequences , Make all S(i) Not more than x? Let's use the predicate to answer this question P(x) Express , Then let P(x) True minimum x Is the answer to the original question .
that x How to get the value ?
My idea is to increase from childhood , Find the right , The smallest one is the sum of the array divided by the number of subsequences divided . for example 1 2 3 2 5 4, that x Just from 6 Start .
Code
numbers=[1,2,3,2,5,4,4]
m=int(input())
nums=sum(numbers)
if nums%m!=0:
a=nums//m+1
else:
a=nums//m
while True:
b=0
for i in range(m-1):
n=0
d=b
for i in range(d,len(numbers)):
temp=sum(numbers[b:i+1])
if temp>a:
b=i
break
elif temp==a:
b=i+1
break
if sum(numbers[b:])<=a:
print(a)
break
else:
a+=1
If you have any shortcomings, please leave a message in the comment area ~~~
边栏推荐
- Section II: structural composition characteristics of asphalt pavement (2) structural layer and performance requirements
- Lianrui electronics made an appointment with you with SIFA to see two network cards in the industry's leading industrial automation field first
- Apply the intelligent OCR identification technology of Shenzhen Yanchang technology to break through the bottleneck of medical bill identification at one stroke. Efficient claim settlement is not a dr
- 49. grouping of acronyms
- Inventory | ICLR 2022 migration learning, visual transformer article summary
- PCB走线到底能承载多大电流
- MySQL nested sorting: first sort and filter the latest data, and then customize the sorting of this list
- Oh my Zsh correct installation posture
- Concurrent search set
- Common methods of tool class objectutil
猜你喜欢

22. Generate parentheses

Network security construction in 5g Era

KD-Tree and LSH

Technology | image motion drive interpretation of first order motion model

The solution "no hardware is configured for this address and cannot be modified" appears during botu simulation

Preliminary test of running vins-fusion with zed2 binocular camera

华为设备配置通过GRE接入虚拟专用网

Preliminary understanding of DFS and BFS

jvm调优六:GC日志分析和常量池详解

Overview of self attention acceleration methods: Issa, CCNET, cgnl, linformer
随机推荐
Opencv learning path (2-4) -- Deep parsing cvtcolor function
Analyze while doing experiments -ndk article -jni uses registernatives for explicit method registration
Introduction to coordinate system in navigation system
Traversal of binary tree -- restoring binary tree by two different Traversals
(十五)红外通信
BP neural network derivation + Example
Retinanet+keras train their own data set to tread on the pit
jvm调优六:GC日志分析和常量池详解
Sealem finance builds Web3 decentralized financial platform infrastructure
White Gaussian noise (WGN)
Pychart displays pictures with imshow
22、生成括号
[project - what are the supporting materials in the annexes? (18 kinds of 2000 word summary)] project plan of innovation and entrepreneurship competition and supporting materials of Challenge Cup entr
Share | guide language image pre training to achieve unified visual language understanding and generation
49. grouping of acronyms
Following the wave of lack of core, Lianrui launched a number of gigabit network card solutions
【入门级基础】Node基础知识总结
Top 100 video information of station B
Oh my Zsh correct installation posture
Support vector machine -svm+ source code