ZOJ 3929 Deque and Balls】的更多相关文章

题目链接 题意:给你n个数,按照顺序依次放入一个双端队列(可放在头部,也可以放在尾部),求xi > xi+1的期望 * 2^n mod (1e9 +7) 分析:期望*2^n=出现这种排法的概率*这种排法的desents数*2^n = 1/(2^(n-1)) * 2^n * 每一种排法每一个数的desents数=2* 每一种排法每一个数字的贡献值. 首先插入xi有两种方法,相当于有两种排法,那么求前缀时ans[i] = ans[i-1] * 2,然后再考虑当前xi的贡献值:如果放在头部,那么要求出…
答案=所有情况中总共递减次数*2 放完i个和放完i-1个之间的递减次数是可以递推的. 有一部分是放完i-1个之后产生的,还有一部分是放完第i个之后新产生的. 注意减去多加的部分. 2的i次方可以打个表,然后就再开一个sum预处理2的i次方的前缀和,就可以递推了. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; +; ; lo…
There are n balls, where the i-th ball is labeled as pi. You are going to put n balls into a deque. In the i-th turn, you need to put the i-th ball to the deque. Each ball will be put to both ends of the deque with equal probability. Let the sequence…
题意:给出一个序列,按照顺序一个一个放入双端队列(可以放在头部也可以放在尾部),一个队列的美丽指数就是数列中a[i]>a[i+1]的个数,求美丽指数的期望*2^n的值. 解题思路:方便起见,我们将a[i]>a[i+1]的情况称为D情况. 由题意可以知道最后得到的序列一共有2^(n-1)个,设ans=所有序列中D情况个数的总和,最后就是求sum/2^(n-1)*2^n = 2*sum 对于将要插入的a[j],sum=原先的D情况总和*2+a[j]产生的D情况-(a[i]=a[j])的情况 如果a…
题目大意:n个数,每个数的大小都在1~n之间.操作n次,第 i 次将第 i 个数放到一个双端队列里面,放到队列两端的概率是相等的.问操作n次之后双端队列中元素满足xi>xi+1的对数的期望,输出的数据为:(期望*2^n)%mod. 题目分析:定义状态dp(i)表示操作 i 次之后的相应期望值.则状态转移方程为: dp(i)=1/2*(dp(i-1)+k1)+1/2*(dp(i-1)+k2)  (两种情况,放在队首和队尾) 其中,k1表示比a(i)小的元素可能与a(i)相邻的总次数,k2表示比a(…
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i…
在今天三黑(恶意评分刷上去的那种)两紫的智推中,突然出现了P3834 [模板]可持久化线段树 1(主席树)就突然有了不详的预感2333 果然...然后我gg了!被大佬虐了! hdu 2665 Kth number 题意就不写了,太经典了(可我还是不会这题,我太菜了) 大佬的题解写的太神仙了,我这么菜的人都看懂了2333,所以我就不写了... 不过这题是真的坑啊...老师在上面讲的时候,我们开始提交(他们交主席树,我交整体二分)然后等讲完我们还没过23333 MLE.TLE.WA(可能还有CE)轮…
SP3946 K-th Number (/2和>>1不一样!!) #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <…
F - Faster, Higher, Stronger Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 2970 Description In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of…
传送门:zoj 3279 Ants Ants Time Limit: 2 Seconds      Memory Limit: 32768 KB echo is a curious and clever girl, and she is addicted to the ants recently. She knows that the ants are divided into many levels depends on ability, also, she finds the number…