CF209A.Multicolored Marbles
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarpus plays with red and blue marbles. He put n marbles from the left to the right in a row. As it turned out, the marbles form a zebroid.
A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are zebroids and sequence (red; red) is not a zebroid.
Now Polycarpus wonders, how many ways there are to pick a zebroid subsequence from this sequence. Help him solve the problem, find the number of ways modulo 1000000007 (109 + 7).
波利卡普斯玩红色和蓝色的弹珠。他从左到右将 $ n $ 颗弹珠排成一行。结果发现,这些弹珠构成了一条“斑马条纹序列”(zebroid)。
一个非空的红蓝弹珠序列被称为斑马条纹序列(zebroid),当且仅当该序列中弹珠的颜色严格交替出现。例如,序列(红;蓝;红)和(蓝)是斑马条纹序列,而序列(红;红)则不是。
现在波利卡普斯想知道:从这个序列中选出一个斑马条纹子序列,共有多少种方法?请你帮他解决这个问题,求出方案数对 $ 1000000007 $(即 $ 10^9 + 7 $)取模的结果。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 106) — the number of marbles in Polycarpus's sequence.
第一行包含一个整数 n(1≤n≤106)—— Polycarpus 序列中弹珠的数量。
输出格式
Print a single number — the answer to the problem modulo 1000000007 (109 + 7).
输出一个数字——该问题答案对 1000000007(109+7)取模的结果。
输入输出样例
输入#1
3
输出#1
6
输入#2
4
输出#2
11
说明/提示
Let's consider the first test sample. Let's assume that Polycarpus initially had sequence (red; blue; red), so there are six ways to pick a zebroid:
- pick the first marble;
- pick the second marble;
- pick the third marble;
- pick the first and second marbles;
- pick the second and third marbles;
- pick the first, second and third marbles.
It can be proven that if Polycarpus picks (blue; red; blue) as the initial sequence, the number of ways won't change.
我们来考虑第一个测试样例。假设 Polycarpus 最初拥有序列(红色;蓝色;红色),那么一共有六种方式选出一个斑马序列(zebroid):
- 选取第一颗弹珠;
- 选取第二颗弹珠;
- 选取第三颗弹珠;
- 选取第一颗和第二颗弹珠;
- 选取第二颗和第三颗弹珠;
- 选取第一颗、第二颗和第三颗弹珠。
可以证明,若 Polycarpus 选择(蓝色;红色;蓝色)作为初始序列,则选取方式的总数不会改变。
输入解题思路,AI测评打分。不知道怎么写?