Hdu1438 key count 1

Source: Internet
Author: User

Link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1438

For the first time, I made a recursive question so seriously. Good question!

If you want to learn more about the problem report, you will have a clear idea. Reading the report is a bad habit, but there is no way to cook .......... Call

Recursive equation:

1 If X is the key, so is X1/2/3/4.

2. If X is not the key, x2/3 is. Then X is composed of 1 and 4, except that all are composed of 1 or 4.

3. If X is not the key, x14 and x41 are. Then the front I-2 is composed of 1, 2, 3, 4. Except for the case where all values are 1 and 4, X is the key and X ends with 1/4.
. Use the B [I] array to represent the number of I-bits ending with 1/4.


# Include <stdio. h>
# Include <math. h>

# Define n 35

Int main ()
{
_ Int64 A [n], B [N]; // A [I] calculates the total number of keys. B [I] calculates the total number of keys ending with 1 or 4.
_ Int64 temp;
Int I;
A [2] = 0;
B [2] = 0;
A [3] = 8;
B [3] = 4;
For (I = 4; I <32; I ++)
{
A [I] = A [I-1] * 4;
A [I] + = (_ int64) (POW (2, I-1) * 2)-4; // key ending with 2 or 3
Temp = (_ int64) Pow (4, I-2)-(_ int64) Pow (2, I-2) * 2-B [I-1];
A [I] + = temp;
B [I] = A [I-1] * 2 + temp;
}
For (I = 2; I <32; I ++)
{
Printf ("n = % d: % i64d \ n", I, a [I]);
}
Return 0;
}

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.