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;
}