Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

ABalobanov's blog

By ABalobanov, history, 8 years ago, In English

How to count number of bracket sequences with n opening brackets and m closing brackets so that the balance never gets negative? I came to this problem thinking about other one(D from previous Open Cup), and I can't solve it in sufficient complexity. Is there a way to do it with n <= 2000, m <= 2000, answering one query in O(1) time or somehow precomputing these values for all i, j <= 2000?

  • Vote: I like it
  • +6
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it +5 Vote: I do not like it

May be Catalan number can be useful for you. You can read it here.

»
8 years ago, # |
  Vote: I like it +18 Vote: I do not like it