Binary sequences

4

1 votes
Dynamic Programming, Algorithms, C++, 3D dynamic programming
Problem

You are given three integers Z,O,K.

Your task is to determine the number of distinct sequences of length Z+O that contains exactly Z zeroes and O ones. Also, the length of longest non-decreasing subsequence in the sequence is of length K.

Note

  • Two sequences are said to be distinct if there exists at least one index where the value of element present is different in both sequences.
  • A non-decreasing subsequence of a is a sequence of integers ap1,ap2,...,apk where p1<p2<..<pk and ap1ap2...apk

Input format

  • The first line contains an integer T that denotes the number of test cases.
  • For each test case:
    • The first line contains three space-separated integers Z,O,K.

Output format

For each test case, print the number of distinct sequences that satisfy the provided conditions.

Note: The result can be a large value, print the output in modulo 109+7 format.

Constraints

1T101K1021Z,O50

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For test case 1:

  • Following are the valid sequences:
    • 1001 : Length of longest non-decreasing subsequence is 3
    • 0011 : Length of longest non-decreasing subsequence is 4
    • 0101 : Length of longest non-decreasing subsequence is 3
    • 0110 : Length of longest non-decreasing subsequence is 3

For test case 2:

  • Following are the valid sequences:
    • 01111 : Length of longest non-decreasing subsequence is 5
    • 10111 : Length of longest non-decreasing subsequence is 4
    • 11011 : Length of longest non-decreasing subsequence is 4
    • 11101 : Length of longest non-decreasing subsequence is 4
    • 11110 : Length of longest non-decreasing subsequence is 4
Editor Image

?