当前位置:网站首页>[7.16] code source - [array division] [disassembly] [select 2] [maximum common divisor]
[7.16] code source - [array division] [disassembly] [select 2] [maximum common divisor]
2022-07-23 15:38:00 【ZhgDgE】
#665. Array partition
The question : Given n ( n ≤ 100 ) n(n\leq 100) n(n≤100) It's an integer , Divide it into just k ( k ≤ 100 ) k(k\leq 100) k(k≤100) Subarray , Find the maximum value of sum operation after summing each sub array .
Answer key :( Dynamic programming ) Code source daily question Div1 Array partition
Ideas : At first I defined d p ( i , j ) dp(i,j) dp(i,j) For the former i i i Each element is divided into j j j The maximum value of the block , The transfer equation is d p ( i , j ) = max ( d p ( k , j − 1 ) & ( s u m ( k + 1 , i ) ) ) dp(i,j)=\max(dp(k,j-1)\&(sum(k+1,i))) dp(i,j)=max(dp(k,j−1)&(sum(k+1,i))) , But that doesn't work . Tell me in detail why not .
First , Each state is essentially a set , Each element in the set corresponds to a weight , According to the topic, we usually require the upper bound or lower bound of the weight of the set ( That is what is usually said max − min \max-\min max−min ), That is, the attributes of the set . If we adopt DP Find this attribute recursively , We must ensure that the attributes of the subsequent state and the attributes of the precursor state are monotonous . How do you understand that ?
We define an independent variable x x x , Its definition domain is the weight value domain of the precursor node ( Of course, there are upper and lower bounds ). According to the recursive equation , Weight value range of subsequent nodes y = f ( x ) y=f(x) y=f(x) . Only when f ( x ) f(x) f(x) It is incremental within the definition field , Only by maintaining the upper bound of the precursor ( Lower bound ), To get the upper bound of the subsequent range ( Lower bound ). If monotonic increase is not satisfied , Then the extreme value of the subsequent state does not necessarily lie on the upper bound of the precursor state ( Lower bound ) obtain . This recursive monotone property of dynamic programming is also important .
Back to the question , Because it's a bit operation , Increasing the value of the predecessor node does not necessarily increase the value of the successor node , Then this method will not work .
The solution to this problem is : Enumerate the binary bits of the answer from the high order , Then judge whether the sequence is divided k The scheme of parts makes the sum greater than or equal to ans, Then decide whether to keep the bit 1 The decision .DP Existence , y ≥ x y\geq x y≥x If and only if ( y & x ) = = x (y\&x)==x (y&x)==x , If there is a segmentation scheme , Every paragraph must meet s u m i & x = = x sum_i\&x==x sumi&x==x , Definition d p ( i , j ) dp(i,j) dp(i,j) Before presentation i Divided into k Whether there is a scheme to make the sum greater than or equal to x,DP The existence of transfer .
AC Code :http://oj.daimayuan.top/submission/290489
#611. Dismantle
The question : Multiple sets of data . Each group is given two numbers X,Y, Ask how many lengths are Y The product of the integer sequence of is X. T ≤ 1 0 5 , X , Y ≤ 1 0 6 T\leq 10^5,X,Y\leq 10^6 T≤105,X,Y≤106 .
Ideas : Split the prime factor and allocate it .
Optimization of the method of splitting qualitative factors ( O ( a ∼ b ) O(a\sim b) O(a∼b) Indicates that the pretreatment time is a a a, The query time is b b b):
- Preprocess to get all primes , Then use only prime numbers to sift , Time complexity O ( n ∼ n ln n ) O(n\sim\frac{\sqrt n}{\ln{\sqrt n}}) O(n∼lnnn)
- Pretreat all numbers with an Ehrlich sieve , Get the prime factor of each number ( The series is log n \log n logn), The time complexity is O ( n × log n ∼ log n ) O(n\times \log n\sim \log n) O(n×logn∼logn)
This problem uses the second optimization . We store all the prime factor preprocessing of a number , Then use it directly .
vector<int> primes[M];
for(int i = 2; i < M; i ++ ){
if(primes[i].size()) continue;
for(int j = i; j < M; j += i){
int t = j, cnt = 0;
while(t % i == 0) cnt ++ , t /= i;
primes[j].push_back(cnt);
}
}
AC Code :http://oj.daimayuan.top/submission/291303
#618. Selection 2
The question :

Answer key :( greedy ) Code source daily question Div1 Selection 2
Ideas : First of all find out m m m . If there is one, the length is m m m The subsequence of satisfies the meaning of the question , Then there must be a length of m m m The subinterval of satisfies the meaning of the question , Because we fix the right endpoint , Move other numbers to the right , The average will only get bigger . In this way, we can find m m m .
Find out m m m after , For each substring that meets the meaning of the topic , Only move the left endpoint to the left , This ensures that the left endpoint moves as far to the left as possible . Still two points .
AC Code :http://oj.daimayuan.top/submission/290739
#131. greatest common divisor
The question : You have a ring , It's on the ring n n n A positive integer . You can cut the ring into sections , Each paragraph contains one or more numbers .
For a segmentation scheme , The degree of beauty is the maximum common divisor of each number and , You want to maximize the beauty of the segmentation program , about k = 1 , 2 , ⋯ , n k=1,2,\cdots,n k=1,2,⋯,n Output the answer .
Answer key :( mathematics / enumeration / Problems on the ring ) Code source daily question Div1 greatest common divisor
Ideas : We divide the rings into k k k Share , that g c d ∣ s i , i ∈ [ 1 , k ] gcd|s_i,i\in [1,k] gcd∣si,i∈[1,k] , namely g c d ∣ ∑ i = 1 k s i = s u m gcd|\sum_{i=1}^k{s_i}=sum gcd∣∑i=1ksi=sum . Let's enumerate s u m sum sum The factor of is g c d gcd gcd . The order of magnitude of the factor can be considered as expectation log n \log n logn , The worst n \sqrt n n Of .
about g c d gcd gcd , We can find out how many segments can be divided at most , Because segments can be merged , The suffix and the maximum are enough . If it is a normal sequence , Then directly find how many numbers in the prefix sum are m o d g c d \bmod gcd modgcd In the sense of 0 0 0 . If it's a ring , We ask how many numbers are in the prefix and m o d g c d \bmod gcd modgcd In the sense of equal .
边栏推荐
- VMware虚拟机下载安装使用教程
- Part I basic information of the project
- 颜值爆表 Redis官方可视化工具来啦,针不戳
- ClickHouse,让查询飞起来!!!
- Matlab simulation of solving multi-objective optimal value based on PSO optimization
- 广州举办镇街农产品质量安全监管员大比武
- [pyGame practice] playing poker? Win or lose? This card game makes me forget to eat and sleep.
- Smart headline: smart clothing forum will be held on August 4, and the whole house smart sales will exceed 10billion in 2022
- Skills to learn before going to primary school
- 开源四足机器人 附设计图及代码「建议收藏」
猜你喜欢

The current situation and history of it migrant workers

The official redis visualization tool is coming. The needle doesn't poke
![[pyGame practice] playing poker? Win or lose? This card game makes me forget to eat and sleep.](/img/ba/a174c5daccef7a6ea72c11dad8601d.png)
[pyGame practice] playing poker? Win or lose? This card game makes me forget to eat and sleep.

VSCode 更新後與tab相關快捷鍵無法使用
![[200 opencv routines] 225. Fourier descriptor for feature extraction](/img/4b/1f373505ffd5c0dbaa5c20431c4b42.png)
[200 opencv routines] 225. Fourier descriptor for feature extraction

Simulink simulation of ESP three-phase SVPWM controller
![[CTFHub]JWT 的头部和有效载荷这两部分的数据是以明文形式传输的,如果其中包含了敏感信息的话,就会发生敏感信息泄露。试着找出FLAG。格式为 flag{}](/img/d0/133d628a304f5c6b5f0d514c9fe222.jpg)
[CTFHub]JWT 的头部和有效载荷这两部分的数据是以明文形式传输的,如果其中包含了敏感信息的话,就会发生敏感信息泄露。试着找出FLAG。格式为 flag{}

Force buckle monotone stack

select......for update 语句的功能是什么? 会锁表还是锁行?

Linux: analysis of the basic use of vim editor
随机推荐
[solve the exception] Flink uploads the jar package to the cluster environment, and the operation report does not serialize the exception
Cookie和Session的区别
多线程一定能优化程序性能吗?
C # calculate the number of times a character appears in the string
自定义封装弹出框(带进度条)
Redis Key没设置过期时间,为什么被主动删除了
800V高压快充落地进程加快均胜电子获5亿欧元项目定点
C语言书写规范
安全作业7.22
STL map operation
VSCode 更新後與tab相關快捷鍵無法使用
【Pygame实战】打扑克牌嘛?赢了输了?这款打牌游戏,竟让我废寝忘食。
Completely uninstall MySQL in centos7
地图附近名片流量主小程序开发
printf函数-转换说明
Solve the problem that kotlin writes the Android project compilation report execution failed for task ': app:kaptdebugkotlin'. Exception
安全合理用电 收获清凉一“夏”
C语言经典例题-逆序打印输入的两位数
C# 计算某个字符在字符串中出现的次数
Redis bloom filter