Problem description
If an arbitrarily contiguous two-bit in the K-binary representation of a natural number n is not an adjacent number, then we say that this number is a K-good number. Ask for the number of K good numbers in the L-bit K-binary number. For example k = 4,l = 2, all k good numbers are 11, 13, 20, 22, 30, 31, 33 total 7. Since this is a large number, please output it to 1000000007 after the modulo value.
Input format
The input contains two positive integers, K and L.
Output format outputs an integer that represents the value after which the answer is modulo 1000000007. Sample Input 4 2 sample output 7 data size and conventions
For 30% of data, KL <= 106;
For 50% data, K <=, L <= 10;
For 100% of data, 1 <= k,l <= 100.
IDEA: Dynamic programming application DP backpack, Dp[i][j], where I represents the number of a few, J for the first place J of the case there are several
Import Java.io.BufferedReader; Import java.io.IOException; Import java.io.inputstreamreader;import java.text.decimalformat;import java.util.*;p ublic class Main {public static void Main (string[] args) throws ioexception{ Scanner in= new Scanner (system.in); int K=in.nextint (); int L=in.nextint (); int mod=1000000007; int dp[][]=new int[105][105]; for (int i = 0; i<k; i++) dp[1][i] = 1; for (int i = 2, i<=l; i++) for (int j = 0; j<k; j + +) for (int x = 0; x<k; x + +) if (x!=j-1&&x!= J+1)//According to test instructions, the standard number is not adjacent to the preceding number { dp[i][j]+=dp[i-1][x]; Dp[i][j]%=mod; } int sum = 0; for (int i = 1; i<k; i++) { sum+=dp[l][i]; Sum%=mod; } SYSTEM.OUT.PRINTLN (sum);} }
Algorithm Training k Good number