Python Indentation
题意翻译
CF909C Python的缩进
Python的代码中不需要写begin、end或者大括号去标记开头或结尾。
我们将考虑一种Python非常简化的子集,它的语句只有两种类型。
每行只写一个简单语句,比如赋值。
For语句是一个较复杂的语句,他们可能包含一个或多个其他的语句。
For语句由一个单独的行组成,以“For”前缀和循环体开头。
循环体是一个语句块,比循环头缩进一级。
循环体可以包含这两种类型的语句。循环体不能为空。
给你一个没有缩进的序列,求有多少种方式添加缩进可以形成一个完整的Python代码。
输入格式:
第一行:N
接下来N行每行一个字符f(for语句)或s(简单语句)。
保证最后一行一定是s(简单语句)。
输出格式:
输出方案数,答案对10^9+7取模。
感谢@2016c01 提供的翻译
题目描述
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An example of a simple statement is assignment.
For statements are compound statements: they contain one or several other statements. For statement consists of a header written in a separate line which starts with "for" prefix, and loop body. Loop body is a block of statements indented one level further than the header of the loop. Loop body can contain both types of statements. Loop body can't be empty.
You are given a sequence of statements without indentation. Find the number of ways in which the statements can be indented to form a valid Python program.
输入输出格式
输入格式
The first line contains a single integer $ N $ ( $ 1<=N<=5000 $ ) — the number of commands in the program. $ N $ lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.
输出格式
Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo $ 10^{9}+7 $ .
输入输出样例
输入样例 #1
4
s
f
f
s
输出样例 #1
1
输入样例 #2
4
f
s
f
s
输出样例 #2
2
说明
In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
`<br></br>simple statement<br></br>for statement<br></br> for statement<br></br> simple statement<br></br>`In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one.
`<br></br>for statement<br></br> simple statement<br></br> for statement<br></br> simple statement<br></br>`or
`<br></br>for statement<br></br> simple statement<br></br>for statement<br></br> simple statement<br></br>`