CF1781F.Bracket Insertion

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vika likes playing with bracket sequences. Today she wants to create a new bracket sequence using the following algorithm. Initially, Vika's sequence is an empty string, and then she will repeat the following actions nn times:

  • Choose a place in the current bracket sequence to insert new brackets uniformly at random. If the length of the current sequence is kk , then there are k+1k+1 such places: before the first bracket, between the first and the second brackets, \ldots , after the kk -th bracket. In particular, there is one such place in an empty bracket sequence.
  • Choose string "()" with probability pp or string ")(" with probability 1p1 - p and insert it into the chosen place. The length of the bracket sequence will increase by 22 .

A bracket sequence is called regular if it is possible to obtain a correct arithmetic expression by inserting characters '+' and '1' into it. For example, sequences "(())()", "()", and "(()(()))" are regular, while ")(", "(()", and "(()))(" are not.

Vika wants to know the probability that her bracket sequence will be a regular one at the end. Help her and find this probability modulo 998244353998\,244\,353 (see Output section).

输入格式

The only line contains two integers nn and qq ( 1n5001 \le n \le 500 ; 0q1040 \le q \le 10^4 ). Here nn is equal to the number of bracket insertion operations, and the probability that Vika chooses string "()" on every step of the algorithm is equal to p=q104p = q \cdot 10^{-4} .

输出格式

Print the probability that Vika's final bracket sequence will be regular, modulo 998244353998\,244\,353 .

Formally, let M=998244353M = 998\,244\,353 . It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q} , where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M} . Output the integer equal to pq1modMp \cdot q^{-1} \bmod M . In other words, output such an integer xx that 0x<M0 \le x < M and xqp(modM)x \cdot q \equiv p \pmod{M} .

输入输出样例

  • 输入#1

    1 7500

    输出#1

    249561089
  • 输入#2

    2 6000

    输出#2

    519087064
  • 输入#3

    5 4000

    输出#3

    119387743

说明/提示

In the first example, Vika will get a regular bracket sequence () with probability p=34p = \frac{3}{4} , and she will get an irregular bracket sequence )( with probability 1p=141 - p = \frac{1}{4} . The sought probability is 34\frac{3}{4} , and 24956108943(mod998244353)249\,561\,089 \cdot 4 \equiv 3 \pmod{998\,244\,353} .

In the second example, the sought probability is 1125\frac{11}{25} .

首页