#P3666. [USACO17OPEN] COWBASIC P

    ID: 1108 Type: RemoteJudge 1000ms 125MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>模拟2017USACO矩阵乘法构造

[USACO17OPEN] COWBASIC P

题目描述

Bessie has invented a new programming language, but since there is no compiler yet, she needs your help to actually run her programs.

COWBASIC is a simple, elegant language. It has two key features: addition and MOO loops. Bessie has devised a clever solution to overflow: all addition is done modulo 109+710^9+7. But Bessie's real achievement is the MOO loop, which runs a block of code a fixed number of times. MOO loops and addition can, of course, be nested.

Given a COWBASIC program, please help Bessie determine what number it returns.

Bessie研制出了一种新的编程语言,但是因为还没有设计编译器的缘故,她需要你的帮助来运行她编的程序。

COWBASIC语言是一种简单的、优美的语言。它有两个关键功能:变量相加和MOO循环。对于可能的溢出问题,Bessie想出了一个很好的方法,所有的变量加法都要以10^9+7为模。但是Bessie设计的COWBASIC语言中真正成功之处是可以运行一段固定数量的代码的MOO循环。MOO循环和加法是可以嵌套的

给你一段COWBASIC程序,请你帮助Bessie确定这个程序段将会返回什么数值。

输入格式

You are given a COWBASIC program at most 100 lines long, with each line being at most 350 characters long. A COWBASIC program is a list of statements.

<variable> = <expression>

<literal> MOO {
<list of statements>
}

RETURN <variable>
<literal>

<variable>

( <expression> ) + ( <expression> )

There are three types of statements:

There are three types of expressions:

A literal is a positive integer at most 100,000.

A variable is a string of at most 10 lowercase English letters.

It is guaranteed that no variable will be used or RETURNed before it is defined. It is guaranteed that RETURN will happen exactly once, on the last line of the program.

你将会得到一段最长为100行的COWBASIC程序,每行的长度最长为350个字符。COWBASIC语言的结构和类型如下所述:

这是COWBASIC语言的三种主要结构:

<变量>=<表达式> //赋值结构

<数字(循环次数)>MOO{ //循环结构

<一系列的表达式(也就是循环部分)>

} RETURN <变量> //输出结构 把return的变量输出就行了

这是COWBASIC语言的三种类型(我是这么理解的)

<数字> 这些数字是小于100,000正整数

<变量> 这些变量名字是一串10个以内的小写英文字母

(<表达式>)+(<表达式>) //注意:这是COWBASIC中变量加法的表达方法,详见样例

我们保证返回的变量是已定义的,RETURN(输出结构)将只会出现一次且在程序的最后一行

输出格式

Output a single positive integer, giving the value of the RETURNed variable.

输出返回的变量值(有符号的整形数字)

说明:

x = 1
10 MOO {
x = ( x ) + ( x )
}
RETURN x
1024
n = 1
nsq = 1
100000 MOO {
100000 MOO {
nsq = ( nsq ) + ( ( n ) + ( ( n ) + ( 1 ) ) )
n = ( n ) + ( 1 )
}
}
RETURN nsq
4761

提示

Scoring

In 20 percent of all test cases - MOO loops are not nested.

In another 20 percent of all test cases - The program only has 1 variable. MOO loops can be nested.

In the remaining test cases, there are no further restrictions.

评分标准

20%数据:MOO循环不嵌套

另外20%数据:程序只有一个变量,MOO循环可嵌套

其他数据没有多余限制(即最长100行,每行最长350字符)

感谢@psk2016 提供的翻译