[Group] [NOIP2019 JZOJ A simulation 2019.9.11] Ball (Ball)

topic

[Problems] Description
small barrels T and n have 2n - 1 ball, of which the i-th bucket can hold before 2i - 1 ball. Each bucket can only
install a ball.
Now take a small T m m barrels and balls, and the balls are placed in each of these buckets.
This program asked how many.
Two programs differ if and only if you select a different barrel or ball or put different in both programs with a bucket
ball.
Since the number of programs may be large, so only the required result of digital-analog 998244353 embodiment.
[Input format
to read from the input file in ball.in.
A first line integer T, denotes the number of data sets.
Next T lines of two integers n, m, have the meaning] [Problem Description.
[Output format]
output to a file ball.out in.
T total output lines, each represents an integer answer a set of data.
Sample input [1]
. 4
1 1
2 1
2 2
. 3 2
[output] Sample 1
142
18 is
[sample 1] described
for the case of n = m = 1, only select the first ball and a first barrel, and a first ball on the first
two buckets which a solution.
For n =, m = 22 in the case, will select all the tub, the first bucket must put the first ball, in
It is the second bucket can put the second or third ball, a total of two programs.
Sample input [2]
. 4
1000. 1
10000. 1
100000. 1
1000000. 1
[output] Sample 2
1000000
100000000
17556470
757402647

To 100% of the test point to ensure that 1 ≤ T ≤ 105, 1 ≤ m ≤ n ≤ 107.

Thinking

Set f [i] [j] for the i-th bucket by, j balls program number
to find the playing table laws have F [n-] [R & lt] = C (n-, R & lt) 2 * R & lt!

prove:

Here Insert Picture Description

Code

#include<bits/stdc++.h>
using namespace std;
#define mo 998244353
#define N 10000077
#define ll long long
int n,m;
ll fac[N];
ll unfac(ll x)
{
	ll res=1;
	for (int y=mo-2;y;y>>=1,x=x*x%mo)
		if (y&1)
			res=res*x%mo;
	return res; 
}
ll sqr(ll x){return x*x%mo;}
int main()
{
	freopen("ball.in","r",stdin);
	freopen("ball.out","w",stdout);
	fac[0]=1;
	for (int i=1;i<=N;++i)
		fac[i]=fac[i-1]*i%mo;
	int T;
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d%d",&n,&m);
		printf("%lld\n",sqr(fac[n]*unfac(fac[n-m])%mo)*unfac(fac[m])%mo);
	}
	return 0;
}
Published 703 original articles · won praise 392 · Views 140,000 +

Guess you like

Origin blog.csdn.net/Eric1561759334/article/details/100786006