일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Codeforces
- 대수학
- ccw
- round 424
- round 420
- algebra
- 알고리즘
- 이베이트
- persistent segment tree
- persistent indexed tree
- 마일리지
- acmicpc
- k번째 수
- 아시아나
- subgroup
- BOJ
- Ebate Korea
- Algebraic Geometry
- finite group
- indexed tree
- 이베이트미국
- Algorithm
- 백준
- 대한항공
- 구간쿼리
- self balancing binary search tree
- Ebate USA
- gallian
- 이베이트코리아
- 7469
- Today
- Total
[Round#420 Div.2] E. Okabe and El Psy Kongroo 본문
Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as all points (x, y) such that x and y are non-negative. Okabe starts at the origin (point (0, 0)), and needs to reach the point (k, 0). If Okabe is currently at the point (x, y), in one step he can go to (x + 1, y + 1), (x + 1, y), or (x + 1, y - 1).
Additionally, there are n horizontal line segments, the i-th of which goes from x = ai to x = bi inclusive, and is at y = ci. It is guaranteed that a1 = 0, an ≤ k ≤ bn, and ai = bi - 1 for 2 ≤ i ≤ n. The i-th line segment forces Okabe to walk with y-value in the range 0 ≤ y ≤ ciwhen his x value satisfies ai ≤ x ≤ bi, or else he might be spied on. This also means he is required to be under two line segments when one segment ends and another begins.
Okabe now wants to know how many walks there are from the origin to the point (k, 0) satisfying these conditions, modulo 109 + 7.
The first line of input contains the integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1018) — the number of segments and the destination xcoordinate.
The next n lines contain three space-separated integers ai, bi, and ci (0 ≤ ai < bi ≤ 1018, 0 ≤ ci ≤ 15) — the left and right ends of a segment, and its y coordinate.
It is guaranteed that a1 = 0, an ≤ k ≤ bn, and ai = bi - 1 for 2 ≤ i ≤ n.
Print the number of walks satisfying the conditions, modulo 1000000007 (109 + 7).
1 3
0 3 3
4
2 6
0 3 0
3 10 2
4
The graph above corresponds to sample 1. The possible walks are:
The graph above corresponds to sample 2. There is only one walk for Okabe to reach (3, 0). After this, the possible walks are:
x좌표가 a1~a2, a2~a3, ... , an ~ a(n+1) 인 수평선이 n개 존재할 때, 최초 (0,0)에서 시작하여 (k,0)까지 가는 경우의 수를 구하는 문제이다
다만 수평선 위로는 지나갈 수 없고, (x, y)에서 한번 이동할 때 마다 (x+1,y) or (x+1, y-1) or (x+1, y+1) 세방향으로만 이동할 수 있다.
D[i][j] = (ai, j) 까지 이동하는 경우의 수라고 정의하면
가 됨을 귀납적으로 알 수 있다. 따라서 행렬곱을 이용하면 log시간복잡도만에 DP를 계산할 수 있다.
'Algorithm > CodeForces' 카테고리의 다른 글
[Round#424 Div2] E. Cards Sorting (0) | 2017.07.16 |
---|---|
[Round#424 Div2] C.Jury Marks (0) | 2017.07.15 |
[Round#420 Div.2] C. Okabe and Boxes (0) | 2017.06.26 |
[Round#420 Div.2] B. Okabe and Banana Trees (0) | 2017.06.26 |
[Round#419 Div.2] D. Karen and Test (0) | 2017.06.21 |