این مسابقه در تاریخ پنج شنبه ۱۴ دی به صورت حضوری در سایت دانشکده برق و کامپیوتر دانشگاه تهران برگزار شد.

K- Parentheses


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Saman loves brackets (or parentheses). He calls a sequence of ‘(’ and ‘)’ characters a “valid bracket sequence” if either:

  • It’s an empty sequence, or
  • For each open bracket, we can find a closed bracket on its right such that the substring between these two brackets forms a valid bracket sequence, and such that after removing that substring, the remaining brackets also form a valid bracket sequence.

For example, (()) and ()() are both valid, while )( and ())(() are not.

Furthermore, he calls a string of parentheses “kk-valid” if, f, after adding kk open brackets to its left and kk closed brackets to its right, it is valid (either because it was valid before, or because it became valid). For example )( and ())(() are both 11-valid, while ))(( is 2-valid.

Saman is curious to find for any given nn and kk how many bracket sequences there are with length 2n2n that are kk-valid. Because the result may be very large, Saman is only interested in its remainder after dividing it by 109+710^9 + 7.

Help Saman by writing a program that quickly calculates this number for QQ different queries.

input🔗

The first line contains one integer QQ, the number of queries Saman is interested in.

The next QQ lines contain each a pair of integers nin_i and kik_i.

1n1051 \leq n \leq 10^5 1ni,ki1061 \leq n_i, k_i \leq 10^6

output🔗

You need to write QQ lines containing each the result of the ii-th query: for each query, print the number of strings of length 2ni2n_i that are kik_i-valid, modulo 109+710^9 + 7

example🔗

sample input 1🔗

3
2 1
4 2
5 3
Plain text

sample output 1🔗

5
62
242
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.