HBC225351数字比较Redundant Binary Notation题解

人生如戏 算法基础篇 29 0
全网最全C++题库,助您快速提升编程技能!题库丰富多样,涵盖各个领域,让您在练习中不断成长!
d1d0 in redundant binary notation, the equivalent decimal number is dl2l+dl12l1++d121+d020d_{l} · 2^{l} + d_{l1} · 2^{l1} + cdots + d_{1} · 2^{1} + d_{0} · 2^{0}dl2l+dl12l1++d121+d020. Redundant binary notation can allow carryless arithmetic, and thus has applications in hardware design and even in the design of worst-case data structures. For example, consider insertion into a standard binomial heap. This operation takesOOO worst-case time butOOO amortized time. This is because the binary number representing the total number of elements in the heap can be incremented in OOO worst-case time and OOO amortized time. By using a redundant binary representation of the individual binomial trees in a binomial heap, it is possible to improve the worst-case insertion time of binomial heaps to OOO. However, none of that information is relevant to this question. In this question, your task is simple. Given a decimal number NNN and the digit upper bound ttt, you are to count the number of possible representations NNN has in redundant binary notation with each digit in range [0,t][0, t][0,t] with no leading zeros.

    Redundant binary notation is similar to binary notation, except instead of allowing only 000’s and 111’s for each digit, we allow any integer digit in the range [0,t][0, t][0,t], where t is some specified upper bound. For example, if t=2t = 2t=2, the digit 222 is permitted, and we may write the decimal number 444 as 100100100, 202020, or 121212. If t=1t = 1t=1, every number has precisely one representation, which is its typical binary representation. In general, if a number is written as dldl−1…d1d0d_{l}d_{l−1} dots d_{1}d_{0}dl​dl−1​…d1​d0​ in redundant binary notation, the equivalent decimal number is dl⋅2l+dl−1⋅2l−1+⋯+d1⋅21+d0⋅20d_{l} · 2^{l} + d_{l−1} · 2^{l−1} + cdots + d_{1} · 2^{1} + d_{0} · 2^{0}dl​⋅2l+dl−1​⋅2l−1+⋯+d1​⋅21+d0​⋅20.     Redundant binary notation can allow carryless arithmetic, and thus has applications in hardware design and even in the design of worst-case data structures. For example, consider insertion into a standard binomial heap. This operation takes O(log⁡n)O(log n)O(logn) worst-case time but O(1)O(1)O(1) amortized time. This is because the binary number representing the total number of elements in the heap can be incremented in O(log⁡n)O(log n)O(logn) worst-case time and O(1)O(1)O(1) amortized time. By using a redundant binary representation of the individual binomial trees in a binomial heap, it is possible to improve the worst-case insertion time of binomial heaps to O(1)O(1)O(1).     However, none of that information is relevant to this question. In this question, your task is simple. Given a decimal number NNN and the digit upper bound ttt, you are to count the number of possible representations NNN has in redundant binary notation with each digit in range [0,t][0, t][0,t] with no leading zeros.

HBC225351数字比较Redundant Binary Notation题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)

标签: HBC225351数字比较Redundant Binary Notation题解