A8771 | Wall Bars
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 heights $n-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 constructionManao 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 (10^{9}+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.
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 heights $n-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 constructionManao 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 (10^{9}+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.
输入格式
A single line contains two space-separated integers, $n$ and $h$ ( $1<=n<=1000$ , $1<=h<=min(n,30)$ ).
输出格式
In a single line print the remainder after dividing the number of designs by $1000000009 (10^{9}+9)$ .
输入输出样例
输入 #1
5 1
输出 #1
4
输入 #2
4 2
输出 #2
148
输入 #3
4 3
输出 #3
256
输入 #4
5 2
输出 #4
376
Consider several designs for $h=2$ . A design with the first bar sticked out in direction $d_{1}$ , the second — in direction $d_{2}$ and so on ( $1<=d_{i}<=4$ ) is denoted as string $d_{1}$ $d_{2}$ $...$ $d_{n}$ .
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted