#P13566. 「CZOI-R5」青蛙的旅行

    ID: 14394 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP洛谷原创O2优化前缀和洛谷比赛

「CZOI-R5」青蛙的旅行

Background

Little L is a frog, and he is now preparing to travel in City A.

Problem Description

City A is an n×mn\times m matrix. There is a given number kk. There is also a variable ww, initially 00. Let (r,c)(r,c) denote the cell in row rr and column cc.

In this matrix, there are tt special points. The ii-th one is at (xi,yi)(x_i,y_i) with type pip_i (pi{1,2}p_i\in\{1,2\}). If pi=2p_i=2, it has an additional attribute sis_i. It is guaranteed that there do not exist i,ji,j such that iji\neq j and xi=xj,yi=yjx_i=x_j,y_i=y_j.

Little L starts at (1,1)(1,1). He can perform any number of one of the following jump operations until he reaches (n,m)(n,m). Suppose he is currently at (a,b)(a,b):

  • Choose an hh such that 0hk0\le h\le k, and there does not exist 1ih1\le i\le h such that (a+i,b)(a+i,b) is a type 22 special point. Then jump to (a+h+1,b)(a+h+1,b).
  • Choose an hh such that 0hk0\le h\le k, and there does not exist 1ih1\le i\le h such that (a,b+i)(a,b+i) is a type 22 special point. Then jump to (a,b+h+1)(a,b+h+1).
  • Choose an hh such that 0hk0\le h\le k, and there does not exist 1ih1\le i\le h such that (a+i,b+i)(a+i,b+i) is a type 22 special point. Then jump to (a+h+1,b+h+1)(a+h+1,b+h+1).

After each jump, suppose it lands at (X,Y)(X,Y). If (X,Y)(X,Y) is the ZZ-th special point, then:

  • If pZ=1p_Z=1, then ww+1w\leftarrow w+1.
  • If pZ=2p_Z=2, let wwsZw\leftarrow w-s_Z.

If in some plan, at any moment w<0w<0, or at any moment (X,Y)(X,Y) is not inside the matrix, then this plan is invalid.

Ask for the number of valid plans to reach (n,m)(n,m), modulo 109+710^9+7. Two plans are different if and only if the sequences of (X,Y)(X,Y) visited each time are different.

Input Format

The first line contains 44 integers n,m,k,tn,m,k,t.

The next tt lines each start with an integer pip_i, then:

  • If pi=1p_i=1, input 22 integers xi,yix_i,y_i, representing a type 11 special point.
  • If pi=2p_i=2, input 33 integers xi,yi,six_i,y_i,s_i, representing a type 22 special point.

Output Format

Output one integer on the first line, the answer.

3 3 1 2
1 1 3
2 2 3 1
15
3 3 1 0
22

Hint

[Sample Explanation #1]

Note: Each point below represents a cell. A red arrow is one jump, and the tail of the arrow is (X,Y)(X,Y). Yellow points are special points with pi=1p_i=1. Green points are special points with pi=2p_i=2.

The following 1515 plans are valid:

The following 55 plans are invalid, because in these plans, after Little L reaches (2,3)(2,3), w=1<0w=-1<0:

The following 22 plans are invalid, because in these plans, Little L jumps over a special point with pi=2p_i=2:

[Sample Explanation #2]

Since there are no special points, in sample explanation #1, the 1515 valid plans shown and the 77 invalid plans are all valid in sample #2, so the answer is 2222.

[Constraints]

This problem uses bundled testdata.

  • Subtask #1 (15 pts15\text{ pts}): n,m8n,m\le8.
  • Subtask #2 (25 pts25\text{ pts}): k=0k=0.
  • Subtask #3 (25 pts25\text{ pts}): t=0t=0.
  • Subtask #4 (35 pts35\text{ pts}): no additional constraints.

For 100%100\% of the data, 1xin1801\le x_i\le n\le180, 1yim1801\le y_i\le m\le180, 0kmax{n,m}+10\le k\le \max\{n,m\}+1, 0tn×m20\le t\le n\times m-2, pi{1,2}p_i\in\{1,2\}, 1si3561\le s_i\le356.

It is guaranteed that no two pairs (xi,yi)(x_i,y_i) are the same, and it is guaranteed that (xi,yi)(1,1)(x_i,y_i)\neq(1,1) and (xi,yi)(n,m)(x_i,y_i)\neq(n,m).

Translated by ChatGPT 5