2015 Multi-University Training Contest 9 hdu 5396 Expression
Expression
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 175 Accepted Submission(s): 95
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\leq n \leq 100)$.
The second line contains n integers $a_1,a_2,⋯,a_n\quad(0≤a_i \leq 10^9)$.
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 $10^9+7$.
Two numbers are considered different when they are in different positions.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
const LL mod = ;
LL dp[maxn][maxn],c[maxn][maxn] = {},f[maxn] = {};
void init() {
for(int i = ; i < maxn; ++i) {
c[i][] = c[i][i] = ;
f[i] = f[i-]*i%mod;
for(int j = ; j < i; ++j)
c[i][j] = (c[i-][j-] + c[i-][j])%mod;
}
}
char op[maxn];
int main() {
init();
int n;
while(~scanf("%d",&n)) {
memset(dp,,sizeof dp);
for(int i = ; i < n; ++i)
scanf("%I64d",&dp[i][i]);
scanf("%s",op);
for(int i = ; i <= n; ++i) {
for(int j = ; j + i <= n; ++j) {
for(int k = j,t = j + i -; k < t; ++k) {
LL tmp;
if(op[k] == '+')
tmp = (f[t-k-]*dp[j][k] + f[k-j]*dp[k+][t])%mod;
else if(op[k] == '-') {
tmp = (f[t-k-]*dp[j][k] - f[k-j]*dp[k+][t])%mod;
tmp = (tmp + mod)%mod;
} else if(op[k] == '*') tmp = dp[j][k]*dp[k+][t]%mod;
tmp = tmp*c[t-j-][k-j]%mod;
dp[j][t] = (dp[j][t] + tmp + mod)%mod;
}
}
}
printf("%I64d\n",dp[][n-]);
}
return ;
}
2015 Multi-University Training Contest 9 hdu 5396 Expression的更多相关文章
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- 2015 Multi-University Training Contest 8 hdu 5385 The path
The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 2015 Multi-University Training Contest 6 hdu 5362 Just A String
Just A String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence
Easy Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
随机推荐
- Spring注解@RequestMapping请求路径映射问题
@RequestMapping请求路径映射,假设标注在某个controller的类级别上,则表明訪问此类路径下的方法都要加上其配置的路径.最经常使用是标注在方法上.表明哪个详细的方法来接受处理某次请求 ...
- JavaScript特效之前进,后退(返回上一级)
在页面上增加前进,后退(返回上一级)功能: 方式一:使用函数 <script> function goback(){ history.go(-1);//返回或者history.back( ...
- 基于UEFI和GPT模式下U盘安装windows8.1和Linux双启动教程
首先作以下准备: 1.一个8G以上的U盘,用的时候会格式化,建议为空 2.分区助手软件,官网下载链接 3.一个linux系统,这里用同学推荐的Fedora 26,官网下载链接 4.rufus 创建U盘 ...
- 关联查询之map的延伸使用方法
<select id="front.sort.selectListall" parameterType="myshop.services.front.sort.be ...
- JavaScript大数组如何根据对象的key快速找到并删除
查找:上代码. function isBigEnough(element) { return element >= 15; } var ret1 = [12, 5, 8, 130, 44].fi ...
- 常用框架(一):spring+springMvc+mybatis+maven
项目说明: (1) 本例采用 maven web 工程做例子讲解 (2) 利用mybaits 提供的代码生成工具自动生成代码(dao接口,sql mapper映射文件,pojo数据库映射类) (3) ...
- hdoj--1151--Air Raid(最大独立集)
Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- hdoj--1829--A Bug's Life(带权并查集)
A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- Node.js:函数
ylbtech-Node.js:函数 1.返回顶部 1. Node.js 函数 在JavaScript中,一个函数可以作为另一个函数的参数.我们可以先定义一个函数,然后传递,也可以在传递参数的地方直接 ...
- SQL Server 2005外围应用配置器
在SQL Server Configuration Manager中,重启“SQL Server(SQL2005)”服务.