A9408 | 2048
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The programmers from the R2 company love playing 2048. One day, they decided to invent their own simplified version of this game — $2^{k}$ on a stripe.
Imagine an infinite in one direction stripe, consisting of unit squares (the side of each square is equal to the height of the stripe). Each square can either be empty or contain some number.
Initially, all squares are empty. Then at infinity one of the unit squares number 2 or 4 appears. Then the player presses a button once, and the appeared number begins to move towards the beginning of the stripe. Let's assume that some number $x$ moves to the beginning of the stripe, then it will stop if:
1. it either gets in the first square of the stripe;
2. or it is in the square that is preceded by a square with number $y$ $(y≠x)$ . But if number $x$ at some point of time gets to the square with the same number then both numbers add to each other and result in $2x$ . The new number $2x$ continues moving to the beginning of the stripe by the same rules.
After the final stop of the number moving process, the infinity gets a new number 2 or 4 and the process repeats. Read the notes to the test samples to better understand the moving strategy.
I guess you've understood that the game progress fully depends on the order in which numbers 2 and 4 appear. Let's look at some sequence of numbers 2 and 4 in the game. We assume that the sequence is winning if it results in at least one square getting the number greater or equal than $2^{k}$ .
The goal of the game is to make up a winning sequence of $n$ numbers. But not everything is so simple, some numbers in the sequence are identified beforehand. You are given a sequence consisting of numbers 0, 2, 4. Count how many ways there are to replace each 0 of the sequence with 2 or 4 to get a winning sequence.
Imagine an infinite in one direction stripe, consisting of unit squares (the side of each square is equal to the height of the stripe). Each square can either be empty or contain some number.
Initially, all squares are empty. Then at infinity one of the unit squares number 2 or 4 appears. Then the player presses a button once, and the appeared number begins to move towards the beginning of the stripe. Let's assume that some number $x$ moves to the beginning of the stripe, then it will stop if:
1. it either gets in the first square of the stripe;
2. or it is in the square that is preceded by a square with number $y$ $(y≠x)$ . But if number $x$ at some point of time gets to the square with the same number then both numbers add to each other and result in $2x$ . The new number $2x$ continues moving to the beginning of the stripe by the same rules.
After the final stop of the number moving process, the infinity gets a new number 2 or 4 and the process repeats. Read the notes to the test samples to better understand the moving strategy.
I guess you've understood that the game progress fully depends on the order in which numbers 2 and 4 appear. Let's look at some sequence of numbers 2 and 4 in the game. We assume that the sequence is winning if it results in at least one square getting the number greater or equal than $2^{k}$ .
The goal of the game is to make up a winning sequence of $n$ numbers. But not everything is so simple, some numbers in the sequence are identified beforehand. You are given a sequence consisting of numbers 0, 2, 4. Count how many ways there are to replace each 0 of the sequence with 2 or 4 to get a winning sequence.
输入格式
The first line contains two integers $n$ and $k$ $(1<=n<=2000; 3<=k<=11)$ . The next line contains sequence of $n$ integers, each of them is either 0, or 2, or 4.
输出格式
Print a single integer — the number of ways to replace zeroes by numbers 2 or 4 to get a winning sequence. As this number can be rather large, print it modulo $1000000007$ $(10^{9}+7)$ .
输入输出样例
输入 #1
7 4 2 2 4 2 2 2 2
输出 #1
1
输入 #2
1 3 0
输出 #2
0
输入 #3
2 3 0 4
输出 #3
1
输入 #4
5 4 2 0 0 4 4
输出 #4
2
Consider the first example. The beginning of the strip will look as follows:
2 $→$ 4 $→$ 8 $→$ 8 2 $→$ 8 4 $→$ 8 4 2 $→$ 16.
To better understand the game, you can see the original game on http://gabrielecirulli.github.io/2048/. Please note that the game that is described on the strip is slightly different from the original game (when the two numbers add up in the original game, they do not keep moving). Be careful, the game is addictive, there isn't much time for the contest!
2 $→$ 4 $→$ 8 $→$ 8 2 $→$ 8 4 $→$ 8 4 2 $→$ 16.
To better understand the game, you can see the original game on http://gabrielecirulli.github.io/2048/. Please note that the game that is described on the strip is slightly different from the original game (when the two numbers add up in the original game, they do not keep moving). Be careful, the game is addictive, there isn't much time for the contest!
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted