C. Card Game

Consider a game with nn cards (nn is even). Each card has a number written on it, between 11 and nn. All numbers on the cards are different. We say that a card with number xx is stronger than a card with number yy if x>yx>y.

Two players, Alex and Boris, play this game. In the beginning, each of them receives exactly n2n2 cards, so each card belongs to exactly one player. Then, they take turns. Alex goes first, then Boris, then Alex again, and so on.

On a player's turn, he must play exactly one of his cards. Then, if the opponent doesn't have any cards stronger than the card played, the opponent loses, and the game ends. Otherwise, the opponent has to play a stronger card (exactly one card as well). These two cards are removed from the game, and the turn ends. If there are no cards left, the game ends in a draw; otherwise it's the opponent's turn.

Consider all possible ways to distribute the cards between two players, so that each of them receives exactly half of the cards. You have to calculate three numbers:

  • the number of ways to distribute the cards so that Alex wins;
  • the number of ways to distribute the cards so that Boris wins;
  • the number of ways to distribute the cards so that the game ends in a draw.

You may assume that both players play optimally (i. e. if a player can win no matter how his opponent plays, he wins). Two ways to distribute the cards are different if there is at least one card such that, in one of these ways, it is given to Alex, and in the other way, it is given to Boris.

For example, suppose n=4n=4, Alex receives the cards [2,3][2,3], and Boris receives the cards [1,4][1,4]. Then the game may go as follows:

  • if Alex plays the card 22, then Boris has to respond with the card 44. Then, Alex's turn ends, and Boris' turn starts. Boris has only one card left, which is 11; he plays it, and Alex responds with the card 33. So, the game ends in a draw;
  • if Alex plays the card 33, then Boris has to respond with the card 44. Then, Alex's turn ends, and Boris' turn starts. Boris has only one card left, which is 11; he plays it, and Alex responds with the card 22. So, the game ends in a draw.

So, in this case, the game ends in a draw.

Input

The first line contains one integer tt (1≤t≤301≤t≤30) — the number of test cases.

Then, tt lines follow. The ii-th line contains one even integer nn (2≤n≤602≤n≤60).

Output

For each test case, print three integers:

  • the number of ways to distribute the cards so that Alex wins;
  • the number of ways to distribute the cards so that Boris wins;
  • the number of ways to distribute the cards so that the game ends in a draw.

Since the answers can be large, print them modulo 998244353998244353.

Example

input

Copy

 
  

5

2

4

6

8

60

output

Copy

1 0 1
3 2 1
12 7 1
42 27 1
341102826 248150916 1

Note

In the first test case, Alex wins if he receives the card 22 (he plays it, and Boris cannot respond). If Alex receives the card 11, the game ends in a draw.

In the second test case:

  • Alex wins if he receives the cards [3,4][3,4], [2,4][2,4] or [1,4][1,4];
  • Boris wins if Alex receives the cards [1,2][1,2] or [1,3][1,3];
  • the game ends in a draw if Alex receives the cards [2,3][2,3].

思路:

用dp[ i ] 表示第 i 个人赢的方案

首先,平局的可能方案只有1个

假设当前为n, 最大的牌号为n,如果最大的 n 被分到第一个人,那么第一个人先出 n 就已经赢了,所以从剩下n - 1张牌中再任选 n / 2 - 1 张给左边的人,这个贡献是dp[ i ] +=  C_{_{}^{}\textrm{n - 1}}^{n/2}\textrm{}

如果 n 分给了第二个人,那么如果n - 1也分给了第二个人,第一个人是必输的,所以在剩下所有的方案中第一个人能赢的可能方案就是将 n - 1分给第一个人:那么第一个人先出 n - 1,逼出第二个人的 n。

这时局面相当于第二个人先出,共有 n - 2张牌,此时第一个人赢的方案 += 总的方案 - 第二个人赢的方案 - 1(平局),总的方案是C_{n-2}^{(n-2)/2}\textrm{},第二个人赢得方案是dp[n -  2]

所以答案总共为:C_{_{}^{}\textrm{n - 1}}^{n/2}\textrm{}  +  C_{n-2}^{(n-2)/2}\textrm{} - dp[ n - 2 ] - 1

#include
#define int unsigned long long

using namespace std;

const int N = 70, mod = 998244353;

int c[N][N];
int dp[N];

void init() 
{
	for(int i = 0; i < N; i ++)
		for(int j = 0; j <= i; j ++)
			if(!j)
				c[i][j] = 1;
			else
				c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
}

signed main() 
{
	init();
	dp[2] = 1;
	for(int i = 4; i <= 60; i += 2) 
	{
		dp[i] += c[i - 1][i / 2];
		dp[i] += c[i - 2][(i - 2) / 2] - 1 - dp[i - 2];
	}
	int t;
	cin >> t;
	while(t --)
	{
		int n;
		cin >> n;
		cout << ((dp[n]  + mod )% mod) << " " << (c[n][n / 2] - 1 - dp[n] + mod) % mod << " " << "1"<< endl;
	}
}

你可能感兴趣的:(codeforces,算法,动态规划)