CF1473G.Tiles
普及/提高-
通过率:0%
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 .
输入格式
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.
输出格式
Print one integer — the number of paths from the first row to the last row, taken modulo 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