CF1696E.Placing Jinas
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
We say an infinite sequence a0,a1,a2,… is non-increasing if and only if for all i≥0 , ai≥ai+1 .
There is an infinite right and down grid. The upper-left cell has coordinates (0,0) . Rows are numbered 0 to infinity from top to bottom, columns are numbered from 0 to infinity from left to right.
There is also a non-increasing infinite sequence a0,a1,a2,… . You are given a0 , a1 , … , an ; for all i>n , ai=0 . For every pair of x , y , the cell with coordinates (x,y) (which is located at the intersection of x -th row and y -th column) is white if y<ax and black otherwise.
Initially there is one doll named Jina on (0,0) . You can do the following operation.
- Select one doll on (x,y) . Remove it and place a doll on (x,y+1) and place a doll on (x+1,y) .
Note that multiple dolls can be present at a cell at the same time; in one operation, you remove only one. Your goal is to make all white cells contain 0 dolls.
What's the minimum number of operations needed to achieve the goal? Print the answer modulo 109+7 .
输入格式
The first line of input contains one integer n ( 1≤n≤2⋅105 ).
The second line of input contains n+1 integers a0,a1,…,an ( 0≤ai≤2⋅105 ).
It is guaranteed that the sequence a is non-increasing.
输出格式
Print one integer — the answer to the problem, modulo 109+7 .
输入输出样例
输入#1
2 2 2 0
输出#1
5
输入#2
10 12 11 8 8 6 6 6 5 3 2 1
输出#2
2596
说明/提示
Consider the first example. In the given grid, cells (0,0),(0,1),(1,0),(1,1) are white, and all other cells are black. Let us use triples to describe the grid: triple (x,y,z) means that there are z dolls placed on cell (x,y) . Initially the state of the grid is (0,0,1) .
One of the optimal sequence of operations is as follows:
- Do the operation with (0,0) . Now the state of the grid is (1,0,1),(0,1,1) .
- Do the operation with (0,1) . Now the state of the grid is (1,0,1),(1,1,1),(0,2,1) .
- Do the operation with (1,0) . Now the state of the grid is (1,1,2),(0,2,1),(2,0,1) .
- Do the operation with (1,1) . Now the state of the grid is (1,1,1),(0,2,1),(2,0,1),(1,2,1),(2,1,1) .
- Do the operation with (1,1) . Now the state of the grid is (0,2,1),(2,0,1),(1,2,2),(2,1,2) .
Now all white cells contain 0 dolls, so we have achieved the goal with 5 operations.