CF909C.Python Indentation

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 NN ( 1<=N<=50001<=N<=5000 ) — the number of commands in the program. NN 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 109+710^{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>

首页