A880 | Pair Programming--Gold
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
A program consists of a sequence of instructions, each of which is of one of
the following forms:
1. $\times d$, where $d$ is a digit in the range $[0,9]$
2. $+s$, where $s$ is a string denoting the name of a variable. Within a program, all variable names must be distinct.
The result of executing a program is defined to be the expression that results
after applying each instruction in order, starting with $0$. For example, the
result of executing the program $[\times 3,+x,+y,\times 2,+z]$ is the
expression $(0\times 3+x+y)\times 2+z=2\times x+2\times y+z$. Different
programs, when executed may produce the same expressions; for example,
executing $[+w,\times 0,+y,+x,\times 2,+z, \times 1]$ would also result in the
expression $2\times x+2\times y+z$.
Bessie and Elsie each have programs of $N$ ($1\le N\le 2000$) instructions.
They will interleave these programs to produce a new program of length $2N$.
Note that there are $\frac{(2N)!}{N!\times N!}$ ways to do this, but not all
such programs, when executed, will produce distinct expressions.
Count the number of distinct expressions that may be produced by executing
Bessie and Elsie's interleaved program, modulo $10^9+7$.
Each input contains $T$ ($1\le T\le 10$) test cases that should be solved
independently. It is guaranteed that the sum of $N$ over all test cases does
not exceed $2000$.
the following forms:
1. $\times d$, where $d$ is a digit in the range $[0,9]$
2. $+s$, where $s$ is a string denoting the name of a variable. Within a program, all variable names must be distinct.
The result of executing a program is defined to be the expression that results
after applying each instruction in order, starting with $0$. For example, the
result of executing the program $[\times 3,+x,+y,\times 2,+z]$ is the
expression $(0\times 3+x+y)\times 2+z=2\times x+2\times y+z$. Different
programs, when executed may produce the same expressions; for example,
executing $[+w,\times 0,+y,+x,\times 2,+z, \times 1]$ would also result in the
expression $2\times x+2\times y+z$.
Bessie and Elsie each have programs of $N$ ($1\le N\le 2000$) instructions.
They will interleave these programs to produce a new program of length $2N$.
Note that there are $\frac{(2N)!}{N!\times N!}$ ways to do this, but not all
such programs, when executed, will produce distinct expressions.
Count the number of distinct expressions that may be produced by executing
Bessie and Elsie's interleaved program, modulo $10^9+7$.
Each input contains $T$ ($1\le T\le 10$) test cases that should be solved
independently. It is guaranteed that the sum of $N$ over all test cases does
not exceed $2000$.
输入格式
The first line of the input contains $T$, the number of test cases.
The first line of each test case contains $N$.
The second line of each test case contains Bessie's program, represented by a
string of length $N$. Each character is either a digit $d\in [0,9]$,
representing an instruction of type 1, or the character $+$, representing an
instruction of type 2.
The third line of each test case contains Elsie's program in the same format
as Bessie's.
Within a test case, the variable names among all instructions are distinct.
Note that their actual names are not provided, as they do not affect the
answer.
The first line of each test case contains $N$.
The second line of each test case contains Bessie's program, represented by a
string of length $N$. Each character is either a digit $d\in [0,9]$,
representing an instruction of type 1, or the character $+$, representing an
instruction of type 2.
The third line of each test case contains Elsie's program in the same format
as Bessie's.
Within a test case, the variable names among all instructions are distinct.
Note that their actual names are not provided, as they do not affect the
answer.
输出格式
The number of distinct expressions that may be produced by executing Bessie
and Elsie's interleaved programs, modulo $10^9+7$.
and Elsie's interleaved programs, modulo $10^9+7$.
输入输出样例
输入 #1
4 1 0 1 3 12+ +02 3 0++ ++9 4 5+++ +6+1
输出 #1
1 3 9 9
For the first test case, the two possible interleaved programs are $[\times 1,
\times 0]$ and $[\times 0,\times 1]$. These will both produce the expression
$0$ when executed.
For the second test case, executing an interleaving of $[\times 1,\times 2,
+x]$ and $[+y, \times 0,\times 2]$ could produce one of the expressions $0$,
$x$, or $2\times x$.
\times 0]$ and $[\times 0,\times 1]$. These will both produce the expression
$0$ when executed.
For the second test case, executing an interleaving of $[\times 1,\times 2,
+x]$ and $[+y, \times 0,\times 2]$ could produce one of the expressions $0$,
$x$, or $2\times x$.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted