0820 T2 添加符号
来源:互联网 发布:显示屏编辑软件 编辑:程序博客网 时间:2024/05/17 21:56
原题链接
30 pts
枚举每一种情况,求答案,最后求和
时间复杂度O(2^n *n)
Another 30 pts
发现:有x个乘号,答案就是n-x
有x个乘号的方案数为C(n, x)
用杨辉三角预处理组合数就好
时间复杂度O(n^2)
90 pts
用f[i]表示前 i 个数字的答案
枚举距离 i 最近的加号前的数字 j
f[i] = ∑(f[j] + 2^(j-1) * (a[j+1] * … * a[i])
100 pts
用p[i]表示a[1] * … * a[i]
f[i] = ∑(f[j] +2^(j-1)*(p[i]/p[j])
f[i] = ∑f[j] + (∑2^(j-1) * p[j]^(-1))*p[i]
代码
#include<cstdio>const int N = 100000 + 5;const int mod = 1000000007;int n, sum, sum1, f[N], p[N], a[N];inline int pow(int a, int p) {//快速幂 int r = 1; for(; p; p>>=1) { if(p & 1) r = 1ll*r*a % mod; a = 1ll*a*a % mod; } return r;}int main() { scanf("%d", &n); sum = 0; sum1 = 1; p[0] = 1; for(int i = 1; i <= n; ++i) { scanf("%d", a+i); p[i] = 1ll*p[i-1]*a[i] % mod;//rt,p数组 f[i] = (sum+1ll*p[i]*sum1) % mod;//rt,f数组 sum = (sum+f[i]) % mod; sum1 = (sum1+1ll*pow(2, i-1)*pow(p[i], mod-2)) % mod; } printf("%d\n", f[n]); return 0;}
阅读全文
0 0
- 0820 T2 添加符号
- t2
- t2
- t2
- T2
- t2
- T2
- Excel批量添加符号
- 数组添加符号输出
- CString 对路径添加‘/‘符号
- oracle 中添加有&符号
- 添加项目符号或编号
- MapX中添加位图符号
- 字符末尾添加其他符号
- Lombok添加@AllArgsConstructor后报错“错误:找不到符号 符号:类 ConstructorProperties ”
- 在金额前添加货币符号
- EXT Grid中添加人民币符号
- Visio中添加《include》包含符号
- 关于卡特兰数的一些小理解
- 188. Best Time to Buy and Sell Stock IV
- 关于Uncaught SyntaxError- Unexpected token o in JSON at position 1,chrome持续报错的相关解析
- 查找和是某一值或者某一范围的的所有可能
- Beautiful Soup 库入门
- 0820 T2 添加符号
- linux下安装pip
- python3.6教程之内置函数(1)
- Java用JFrame、JPanel、Graphics绘图案例讲解
- 数学小知识&总结索引(持续更新)
- render函数和redirect函数
- Firewalld
- angular 引入三方库
- hdu 1576 A/B(扩展欧几里得)