A15031 | Fancy Stack
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Little Fiona has a collection of $n$ blocks of various sizes $a_1, a_2, \ldots, a_n$ , where $n$ is even. Some of the blocks can be equal in size. She would like to put all these blocks one onto another to form a fancy stack.
Let $b_1, b_2, \ldots, b_n$ be the sizes of blocks in the stack from top to bottom. Since Fiona is using all her blocks, $b_1, b_2, \ldots, b_n$ must be a permutation of $a_1, a_2, \ldots, a_n$ . Fiona thinks the stack is fancy if both of the following conditions are satisfied:
- The second block is strictly bigger than the first one, and then each block is alternately strictly smaller or strictly bigger than the previous one. Formally, $b_1 < b_2 > b_3 < b_4 > \ldots > b_{n-1} < b_n$ .
- The sizes of the blocks on even positions are strictly increasing. Formally, $b_2 < b_4 < b_6 < \ldots < b_n$ (remember that $n$ is even).
Two stacks are considered different if their corresponding sequences $b_1, b_2, \ldots, b_n$ differ in at least one position.
Fiona wants to know how many different fancy stacks she can build with all of her blocks. Since large numbers scare Fiona, find this number modulo $998\,244\,353$ .
Let $b_1, b_2, \ldots, b_n$ be the sizes of blocks in the stack from top to bottom. Since Fiona is using all her blocks, $b_1, b_2, \ldots, b_n$ must be a permutation of $a_1, a_2, \ldots, a_n$ . Fiona thinks the stack is fancy if both of the following conditions are satisfied:
- The second block is strictly bigger than the first one, and then each block is alternately strictly smaller or strictly bigger than the previous one. Formally, $b_1 < b_2 > b_3 < b_4 > \ldots > b_{n-1} < b_n$ .
- The sizes of the blocks on even positions are strictly increasing. Formally, $b_2 < b_4 < b_6 < \ldots < b_n$ (remember that $n$ is even).
Two stacks are considered different if their corresponding sequences $b_1, b_2, \ldots, b_n$ differ in at least one position.
Fiona wants to know how many different fancy stacks she can build with all of her blocks. Since large numbers scare Fiona, find this number modulo $998\,244\,353$ .
输入格式
Each input contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 2500$ ). Description of the test cases follows.
The first line of each test case contains a single integer $n$ — the number of blocks at Fiona's disposal ( $2 \le n \le 5000$ ; $n$ is even). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ — the sizes of the blocks in non-decreasing order ( $1 \le a_1 \le a_2 \le \dotsb \le a_n \le n$ ).
It is guaranteed that the sum of $n$ over all test cases does not exceed $5000$ .
The first line of each test case contains a single integer $n$ — the number of blocks at Fiona's disposal ( $2 \le n \le 5000$ ; $n$ is even). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ — the sizes of the blocks in non-decreasing order ( $1 \le a_1 \le a_2 \le \dotsb \le a_n \le n$ ).
It is guaranteed that the sum of $n$ over all test cases does not exceed $5000$ .
输出格式
For each test case, print the number of ways to build a fancy stack, modulo $998\,244\,353$ .
输入输出样例
输入 #1
2 4 1 2 3 4 8 1 1 2 3 4 4 6 7
输出 #1
2 4
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted