Problems > No K Ones in a Row

No K Ones in a Row

Difficulty: 2000 4000 ms 128 MB

dp matrix-exponentiation

Count the binary strings of length N with no K consecutive 1s, modulo 109+7.

Input: one line with two integers N and K.

Output: the count mod 109+7.

Constraints:

  • 1 ≤ N ≤ 1018
  • 1 ≤ K ≤ 6

Sample Tests

Input 1
3 2
Output 1
5
Input 2
1 1
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.