HBC209778FibonacciPartition题解

三分之二給你 算法基础篇 52 0
题库丰富多样,涵盖各个领域,全网最全C++题库,让您在练习中不断成长!
The sequence of Fibonacci numbers is defined as: Fn={1,n=12,n=2Fn1+Fn2,otherwiseF_n=begin{cases} 1, & n=1 \ 2, & n=2 \ F_{n-1}+F_{n-2}, & text{otherwise} end{cases}Fn=1,2,Fn1+Fn2,n=1n=2otherwise The first few elements of the sequence are 1,2,3,5,8,13,21,34,…. For a given positive integer nnn, letpartitiontext{partition}partition be the maximum value ofmmm such thatnnn can be expressed as a sum of mmmdistinct Fibonacci numbers. For example, partition=partition=1text{partition}=text{partition}=1partition=partition=1, partition=partition=partition=partition=2text{partition}=text{partition}=text{partition}=text{partition}=2partition=partition=partition=partition=2,partition=partition=3text{partition}=text{partition}=3partition=partition=3. Roundgod has an integerxxx which initially equals 000. She will perform some operations on xxx. For the iii-th operation she will addaiFbia_i cdot F_{b_i}aiFbi to xxx. After each operation, Roundgod wants to know the value of partitiontext{partition}partition. It is guaranteed that after each operation, xxxwill be a positive integer.

The sequence of Fibonacci numbers is defined as: Fn={1,n=12,n=2Fn−1+Fn−2,otherwiseF_n=begin{cases} 1, & n=1 \ 2, & n=2 \ F_{n-1}+F_{n-2}, & text{otherwise} end{cases}Fn​=⎩⎪⎨⎪⎧​1,2,Fn−1​+Fn−2​,​n=1n=2otherwise​ The first few elements of the sequence are 1,2,3,5,8,13,21,34,…1, 2, 3, 5, 8, 13, 21, 34, dots1,2,3,5,8,13,21,34,…. For a given positive integer nnn, let partition(n)text{partition}(n)partition(n) be the maximum value of mmm such that nnn can be expressed as a sum of mmm distinct Fibonacci numbers. For example, partition(1)=partition(2)=1text{partition}(1)=text{partition}(2)=1partition(1)=partition(2)=1, partition(3)=partition(4)=partition(5)=partition(7)=2text{partition}(3)=text{partition}(4)=text{partition}(5)=text{partition}(7)=2partition(3)=partition(4)=partition(5)=partition(7)=2, partition(6)=partition(8)=3text{partition}(6)=text{partition}(8)=3partition(6)=partition(8)=3. Roundgod has an integer xxx which initially equals 000. She will perform some operations on xxx. For the iii-th operation she will add ai⋅Fbia_i cdot F_{b_i}ai​⋅Fbi​​ to xxx. After each operation, Roundgod wants to know the value of partition(x)text{partition}(x)partition(x). It is guaranteed that after each operation, xxx will be a positive integer.

HBC209778FibonacciPartition题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断挑战自我,才能突破极限!全网最全C++题库,让您在编程道路上越走越远。

标签: HBC209778FibonacciPartition题解