期望 zoj3929 Deque and Balls
来源:互联网 发布:淘宝卖家复制宝贝链接 编辑:程序博客网 时间:2024/05/18 19:18
传送门:点击打开链接
题意:一个双端队列,现在有n个数,按顺序插入到双端队列中,可能插在左端,也有可能右端,概率相等。最后插完n个数后,如果存在A[i]>A[i+1],那么权值+1。求最后权值的期望*2^n%1e9+7
思路:求期望最常用的有3种方法。
1.期望dp方程,通过之前某个位置的期望,推算当前的期望,通常拿上一个状态的期望乘以从那个状态转移到当前状态的概率加上当前的权值。
如果没有环,则是直接用dp来递推,如果有环,常会用高斯消元来搞。
2.概率dp,求出最后的所有末状态的dp,并且算出每个状态的权值,把概率乘以权值累加起来。
3.排列组合。对于某种权值,计算它的贡献,即 包括这种权值的状态数/总状态数*权值,然后积累所有权值类型
对于这题,因为最后的概率乘了2^n,我们应该首先就应考虑第3种做法,之后就不多说了,自己去推一下,真的很容易。
#include <map>#include <set>#include <cmath>#include <ctime>#include <stack>#include <queue>#include <cstdio>#include <cctype>#include <bitset>#include <string>#include <vector>#include <cstring>#include <iostream>#include <algorithm>#include <functional>#define fuck(x) cout<<"["<<x<<"]";#define FIN freopen("input.txt","r",stdin);#define FOUT freopen("output.txt","w+",stdout);//#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;typedef long long LL;typedef pair<int, int> PII;const int MX = 1e5 + 5;const int mod = 1e9 + 7;int n, A[MX];LL F[MX], S[MX];int main() { F[0] = 1; for(int i = 1; i < MX; i++) { F[i] = F[i - 1] * 2 % mod; } int T; //FIN; scanf("%d", &T); while(T--) { scanf("%d", &n); memset(S, 0, sizeof(S)); for(int i = 1; i <= n; i++) { scanf("%d", &A[i]); } LL sum = 0, ans = 0; for(int i = 1; i <= n; i++) { ans = (ans + (sum - S[A[i]]) * F[n - i] * 2) % mod; LL t = i <= 2 ? 1 : F[i - 2]; S[A[i]] = (S[A[i]] + t) % mod; sum = (sum + t) % mod; } printf("%lld\n", (ans + mod) % mod); } return 0;}
0 0
- 期望 zoj3929 Deque and Balls
- zoj3929 Deque and Balls 【找规律】
- 【ZOJ3929 The 16th Zhejiang University Programming ContestC】【DP】Deque and Balls n个数放入双端队列2^n种方案有多少个位置
- ZOJ 3929 Deque and Balls
- ZOj 3929Deque and Balls
- ZOJ 3929 Deque and Balls
- ZOJ 3929 Deque and Balls
- ZOJ 3932 Deque and Balls
- ZOJ-3929-Deque and Balls【思维】【好题】
- zoj 3929 Deque and Balls 树状数组 递推
- HDU-5810-Balls and Boxes(方差期望)
- [HDU 5810] Balls and Boxes (随机变量计算期望)
- 数学,期望(Balls and Boxes,HDU 5810)
- hdu5194DZY Loves Balls 期望
- HDU 5570(balls-期望)
- HDU 5570:balls 期望。。。。。。。。。。。。。。。
- ZOJ 3929 Deque and Balls (放球问题_DP思维好题)
- ZJU/ZOJ Deque and Balls 3929 计数:小的情况对总情况的贡献。 小心mod运算陷阱
- VS2008或以上版本的ActiveX控件的测试工具(ActiveX Control Test Container)编译记录
- 【自制】javascript模拟数据库查询及格式化操作
- ZOJ 3713 In 7-bit
- 『大型网站技术架构』(一):架构演化、模式、要素
- 位运算符
- 期望 zoj3929 Deque and Balls
- java类的访问权限
- 康拓展开的应用
- usmart_dev.init(SystemCoreClock/1000000); stm32 战舰的usmart 程序
- 插入排序
- EL表达式取Map集合问题
- (9)Java设计模式 - 外观模式(Facade)
- 用按键精灵自动消除行号失败记
- 『大型网站技术架构』(二):高性能架构