Description
If a natural number N of K binary representation of any two adjacent numbers are not adjacent, then we say that K is the number of good number. The number of good number of requirements L digit hexadecimal K K. For example K = 4, L = 2 time, all the good number K of 7 11,13,20,22,30,31,33. Because of this large number, please output value after modulo 1000000007.
Input
Input contains two positive integers, K and L.
Output
Output an integer value representing the answers to the modulo 1000000007.
Sample Input
4 2
Sample Output
7
HINT
Agreed with the data size
of 30% of the data, KL <= 106;
for 50% of the data, K <= 16, L < = 10;
to 100% of the data, 1 <= K, L < = 100.
Ideas:
Where dp [i] [j], where i is represented by several figures, j j is representative of several first discharge
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <string> 5 #include <math.h> 6 #include <algorithm> 7 #include <vector> 8 #include <stack> 9 #include <queue> 10 #include <set> 11 #include <map> 12 #include <sstream> 13 const int INF=0x3f3f3f3f; 14 typedef long long LL; 15 const int MOD = + 1E9 . 7 ; 16 // const Double the PI = ACOS (-1); . 17 #define the Bug COUT << "---------------------" << endl 18 is const int MAXM = 1e6 + 10 ; . 19 const int MAXN = 1E5 + 10 ; 20 is the using namespace STD; 21 is 22 is int DP [ 105 ] [ 105 ]; // DP [i] [J], where i represents the total how many bits (i <= L), j represents the number of front (J <K) 23 is 24 int main () 25 { 26 is intK, L; 27 Scanf ( " % D% D " , & K, & L); 28 for ( int i = 0 ; i <K; i ++) /// row / first initialized to 1, to facilitate the following for loop i calculation of 2 = 29 DP [ . 1 ] [I] = . 1 ; 30 for ( int I = 2 ; I <= L; I ++ ) 31 is { 32 for ( int J = 0 ; J <K; J ++ ) 33 is { 34 is for ( int G = 0 ; G <K; G ++) 35 { 36 IF ! (= J-G . 1 ! && = G + J . 1 ) /// / nonadjacent about 37 [ { 38 is DP [I] [J] + DP = [I- . 1 ] [G]; // tired line cycle plus DP 39 DP [I] [J]% = MOD; 40 } 41 is } 42 is } 43 is } 44 is LL ANS = 0 ; 45 for ( int I = . 1 ; I <K; I ++) //The last line of accumulation, dp [l] [0] representative of the number starts with 0, no statistics 46 is { 47 ANS + = DP [L] [I]; 48 ANS% = MOD; 49 } 50 the printf ( " % LLD \ n- " , ANS); 51 is return 0 ; 52 is }