Algorithms and Data Structures

  • Profound Academy

    • Status
      • 1
        Implementation
      • 2
        Bitwise operations
      • 3
        Prefix Sums
      • 4
        Sliding window / Two pointers
      • 5
        Modular Arithmetic
      • 6
        Number Theory
      • 7
        Binary Search
      • 8
        Basic Sorting
      • 9
        Greedy Algorithms
      • 10
        Basic Dynamic Programming
      • 11
        Recursion
      • 12
        Linked LIst
      • 13
        Queue & Stack
      • 14
        Binary tree + BST
      • 15
        Divide & Conquer + Advanced Sorting
      • 16
        Heap
      • 17
        Hashing
      • 18
        Graph Representation
      • 19
        BFS

  • Beautiful bit-strings

    We love bit-strings. We especially consider those beautiful if they don’t have k consecutive 0s. Given a length n, can you count the number of different bit-strings of length n that are beautiful?

    Input

    The input contains two integers n and k (1 ≤ k ≤ n ≤ 1000).

    Output

    The program should print the number of beautiful bit-strings of length n. As the answer can be very large, you are asked to print it modulo .

    Examples

    Input
    Output
    5 2
    24

    Explanation

    1. 00100
    1. 00101
    1. 00110
    1. 00111
    1. 01001
    1. 01010
    1. 01011
    1. 01100
    1. 01101
    1. 01110
    1. 01111
    1. 10010
    1. 10011
    1. 10100
    1. 10101
    1. 10110
    1. 10111
    1. 11001
    1. 11010
    1. 11011
    1. 11100
    1. 11101
    1. 11110
    1. 11111
     

    Constraints

    Time limit: 1 seconds

    Memory limit: 512 MB

    Output limit: 1 MB

    To check your solution you need to sign in
    Sign in to continue