「CF268D」Wall Bars

2015年7月6日4,2402

Manao is working for a construction company. Recently, an order came to build wall bars in a children’s park. Manao was commissioned to develop a plan of construction, which will enable the company to save the most money.

After reviewing the formal specifications for the wall bars, Manao discovered a number of controversial requirements and decided to treat them to the company’s advantage. His resulting design can be described as follows:

  • Let’s introduce some unit of length. The construction center is a pole of height n.
  • At heights 1, 2, …, n exactly one horizontal bar sticks out from the pole. Each bar sticks in one of four pre-fixed directions.
  • A child can move from one bar to another if the distance between them does not exceed h and they stick in the same direction. If a child is on the ground, he can climb onto any of the bars at height between 1 and h. In Manao’s construction a child should be able to reach at least one of the bars at heightsn - h + 1, n - h + 2, …, n if he begins at the ground.

The figure to the left shows what a common set of wall bars looks like. The figure to the right shows Manao’s construction
Manao is wondering how many distinct construction designs that satisfy his requirements exist. As this number can be rather large, print the remainder after dividing it by 1000000009 (109 + 9). Two designs are considered distinct if there is such height i, that the bars on the height i in these designs don’t stick out in the same direction.

Input

A single line contains two space-separated integers, n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ min(n, 30)).

Output

In a single line print the remainder after dividing the number of designs by 1000000009 (109 + 9).

Sample test(s)
input

output

input

output

input

output

input

output

Note

Consider several designs for h = 2. A design with the first bar sticked out in direction d1, the second — in directiond2 and so on (1 ≤ di ≤ 4) is denoted as string d1d2dn.

Design “1231” (the first three bars are sticked out in different directions, the last one — in the same as first). A child can reach neither the bar at height 3 nor the bar at height 4.

Design “414141”. A child can reach the bar at height 5. To do this, he should first climb at the first bar, then at the third and then at the fifth one. He can also reach bar at height 6 by the route second  →  fourth  →  sixth bars.

Design “123333”. The child can’t reach the upper two bars.

Design “323323”. The bar at height 6 can be reached by the following route: first  →  third  →  fourth  →  sixth bars.

 

题解

f(i,a,b,c,j)表示前i个踏板放在某根柱子,另外三根柱子最后的踏板与它距离分别为a,b,c,j表示第i号踏板是否有效(从地面能否到达它)

设计出状态后,转移就是考虑i+1号踏板放在哪根柱子上

avatar
1 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
0 Comment authors
Recent comment authors
  Subscribe  
提醒
李天逸

这份代码随便一组数据就WA啊,比如209 21,答案应该是220082456

海伦凯乐

Orz LTY