hdu5396

Expression

Problem Description
Teacher Mai has n numbers a1,a2,⋯,anand n−1 operators(“+”, “-” or “*”)op1,op2,⋯,opn−1, which are arranged in the form a1 op1 a2 op2 a3 ⋯ an.

He wants to erase numbers one by one. In i-th round, there are n+1−i numbers remained. He can erase two adjacent numbers and the operator between them, and then put a new number (derived from this one operation) in this position. After n−1 rounds, there is the only one number remained. The result of this sequence of operations is the last number remained.

He wants to know the sum of results of all different sequences of operations. Two sequences of operations are considered different if and only if in one round he chooses different numbers.

For example, a possible sequence of operations for “1+4∗6−8∗3” is 1+4∗6−8∗3→1+4∗(−2)∗3→1+(−8)∗3→(−7)∗3→−21.

Input
There are multiple test cases.

For each test case, the first line contains one number n(2≤n≤100).

The second line contains n integers a1,a2,⋯,an(0≤ai≤109).

The third line contains a string with length n−1 consisting “+”,”-” and “*”, which represents the operator sequence.

Output
For each test case print the answer modulo 109+7.

Sample Input
3
3 2 1
-+
5
1 4 6 8 3
+*-*

Sample Output
2
999999689
Hint
Two numbers are considered different when they are in different positions.

Author
xudyh

Source
2015 Multi-University Training Contest 9

题目描述

给你一个表达式,然后可以以任意顺序来计算各个符号,要求所有不同情况得到的最后答案的和。

看到100的数据应该就想到了区间dp,现在关键是怎么合并这两个区间,以加法为例
设有x个操作符的左边区间能够得到的结果的集合为{ a1,a2,a3...,al } l = x! ;
右边y个操作符的区间结果的集合为 { b1,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值