21615_BracketExpression

2022-5-16 18:19| 发布者: Hocassian| 查看: 22| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505692278499-Problem List-采集的数据-后羿采集器.html

Pro.ID

21615

Title

Bracket Expression

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21615

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    A string S that consists of bracket (), [] and {} only is considered to be valid:

    (a)  if S is an empty string;

    (b)  if both A and B are valid, and S=AB;

    (c)  if A is valid, and S = (A);

    (d)  if A is valid, and S = [A];

    (e)  if A is valid, and S = {A};

    Given the length n, we can construct many valid bracket strings. For example, suppose n = 4, then there are 18 valid bracket strings, which are listed in alphabetical order as follows: (()), ()(), ()[], (){}, ([]), ({}), [()], [[]], [](), [][], []{}, [{}], {()}, {[]}, {{}}, {}(), {}[], {}{}.

    If we numbered them with integers starting from 0, then string ()[] can be called the 2nd valid bracket string of length 4, and the 14th string is {{}}.

    Now, given the length n, and the index k, your task is to find out which the corresponding valid bracket string is in alphabetical order.

    输入

    Input may contain several test cases. The first line is a positive integer, T ( T ≤ 100 ), the number of test cases below. Each test case contains two integers n, k in a single line, n ( 1 ≤ n ≤ 32, n is even ) is the length of bracket string, and k ( 0 ≤ k ≤ 1018 ) is the index of the valid bracket string that should be found.

    输出

    Description

    A string S that consists of bracket (), [] and {} only is considered to be valid:

    (a)  if S is an empty string;

    (b)  if both A and B are valid, and S=AB;

    (c)  if A is valid, and S = (A);

    (d)  if A is valid, and S = [A];

    (e)  if A is valid, and S = {A};

    Given the length n, we can construct many valid bracket strings. For example, suppose n = 4, then there are 18 valid bracket strings, which are listed in alphabetical order as follows: (()), ()(), ()[], (){}, ([]), ({}), [()], [[]], [](), [][], []{}, [{}], {()}, {[]}, {{}}, {}(), {}[], {}{}.

    If we numbered them with integers starting from 0, then string ()[] can be called the 2nd valid bracket string of length 4, and the 14th string is {{}}.

    Now, given the length n, and the index k, your task is to find out which the corresponding valid bracket string is in alphabetical order.

    Input

    Input may contain several test cases. The first line is a positive integer, T ( T ≤ 100 ), the number of test cases below. Each test case contains two integers n, k in a single line, n ( 1 ≤ n ≤ 32, n is even ) is the length of bracket string, and k ( 0 ≤ k ≤ 1018 ) is the index of the valid bracket string that should be found.

    Output

    For each test case, if the k-th valid string of length n in alphabetical order exists, just output that string, otherwise, output "invalid" (without quotation mark).

    Sample Input

    3
    2 3
    4 2
    1 14

    Sample Output

    invalid
    ()[]
    {{}}

    Source

    样例输入

    3
    2 3
    4 2
    1 14

    样例输出

    invalid
    ()[]
    {{}}

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部