Codeforces #307 (Div. 2) Problem D. Gukiz and Binary Operations

Source: Internet
Author: User

The problem is at first the wrong question. No idea at all.

To later the topic to see the right after, there is a little thought, but still do not do. Only to see the official

The official puzzle is this:

First convert numberkinto binary number system. If some bit ofkIs0 than the result oforOpertion applied for every adjacent pair of those bits in arrayaMust be0, that is no, and adjacent those bits in arrayaIs1. We should count how many times this is fulfilled. If The values were smaller we could count it with simplyDPI=DPI-1 +DPI-2, whereDPI is equal to number of ways to make array od i bits where no both is adjacent ones. With first values dp 1 = 2 and dp 2 = 3, we can see the" This is ordinary Fibonacci number. We can calculate Fibonacci numbers up to 1018 easily by Fast matrix Multip Lication. If some bit at K are 1 than number of ways is 2 n -\t{(number of ways bit is 0)}, which are also easy to calculate. We must be cearful for cases when 2 l smaller than K (solution is 0 then) and when l = or l = 64. Total complexity is.

After seeing it, I probably understood his idea. Consider each bits as a step, according to the multiplication principle, the total scheme number = The product of the number of schemes per bit.

If a binary value of K is zero, it is found that each adjacent element cannot be 1. Then DP, which is the Fibonacci sequence, matrix multiplication O (log n) No pressure

If one of the k's binary values is 1, then there must be a value of two adjacent elements of 1, and then found f[n]=2^ (n-1) +f[n-1] answer is 2*f[n-1], but this is very uncomfortable. Considering that this is a count class problem, from the negative side, the scheme is 2^n-dp[n] (Dp[n] refers to the value of a bits when it is zero), and then cool.

Codeforces #307 (Div. 2) Problem D. Gukiz and Binary Operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.