CF1473G.Tiles
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged.
The road is constructed as follows:
- the first row consists of 1 tile;
- then a1 rows follow; each of these rows contains 1 tile greater than the previous row;
- then b1 rows follow; each of these rows contains 1 tile less than the previous row;
- then a2 rows follow; each of these rows contains 1 tile greater than the previous row;
- then b2 rows follow; each of these rows contains 1 tile less than the previous row;
- ...
- then an rows follow; each of these rows contains 1 tile greater than the previous row;
- then bn rows follow; each of these rows contains 1 tile less than the previous row.
An example of the road with n=2, a1=4, b1=2, a2=2, b2=3. Rows are arranged from left to right.
You start from the only tile in the first row and want to reach the last row (any tile of it). From your current tile, you can move to any tile in the next row which touches your current tile.
Calculate the number of different paths from the first row to the last row. Since it can be large, print it modulo 998244353.
考虑一条由若干行组成的道路。每行被划分为若干个矩形砖块,且同一行内的所有砖块均相同。第一行恰好包含一个矩形砖块。请参见下方图片,了解砖块的排列方式。
该道路按如下方式构建:
- 第一行包含 1 块砖;
- 接着是 a1 行,每一行比前一行多 1 块砖;
- 接着是 b1 行,每一行比前一行少 1 块砖;
- 接着是 a2 行,每一行比前一行多 1 块砖;
- 接着是 b2 行,每一行比前一行少 1 块砖;
- …
- 接着是 an 行,每一行比前一行多 1 块砖;
- 接着是 bn 行,每一行比前一行少 1 块砖。
一个示例:n=2,a1=4,b1=2,a2=2,b2=3。各行从左至右排列。
你从第一行中唯一的砖块出发,目标是到达最后一行(到达最后一行中任意一块砖均可)。在当前砖块上,你可以移动到下一行中与当前砖块相接触的任意一块砖。
请计算从第一行到最后一行的不同路径总数。由于结果可能很大,请对 998244353 取模后输出。
输入格式
The first line contains one integer n (1≤n≤1000).
Then n lines follow. The i-th of them contains two integers ai and bi (1≤ai,bi≤105; ∣ai−bi∣≤5).
Additional constraint on the input: the sequence of ai and bi never results in a row with non-positive number of tiles.
第一行包含一个整数 n(1≤n≤1000)。
接下来有 n 行。其中第 i 行包含两个整数 ai 和 bi(1≤ai,bi≤105;∣ai−bi∣≤5)。
输入的附加约束:ai 和 bi 的序列永远不会导致某一行的瓷砖数量为非正数。
输出格式
Print one integer — the number of paths from the first row to the last row, taken modulo 998244353.
输出一个整数——从第一行到最后一行的路径数量,对 998244353 取模。
输入输出样例
输入#1
2 4 2 2 3
输出#1
850
输入#2
3 4 1 2 3 3 1
输出#2
10150
输入#3
8 328 323 867 868 715 718 721 722 439 435 868 870 834 834 797 796
输出#3
759099319
输入解题思路,AI测评打分。不知道怎么写?