ZOJ 3929 Deque and Balls
答案=所有情况中总共递减次数*2
放完i个和放完i-1个之间的递减次数是可以递推的。
有一部分是放完i-1个之后产生的,还有一部分是放完第i个之后新产生的。
注意减去多加的部分。
2的i次方可以打个表,然后就再开一个sum预处理2的i次方的前缀和,就可以递推了。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=+;
long long MOD=1e9+;
long long w[maxn],ans,q[maxn],sum[maxn];
int n,x; long long M(long long a,long long b)
{while(a<) {a=a+b;} a=a%b; return a;} void init()
{
q[]=q[]=; for(int i=;i<=;i++) q[i]=M(*q[i-],MOD);
sum[]=; for(int i=;i<=;i++) sum[i]=M(sum[i-]+q[i],MOD);
} int main()
{
init(); int T; scanf("%d",&T);
while(T--)
{
scanf("%d",&n); memset(w,,sizeof w); ans=;
for(int i=;i<=n;i++)
{
scanf("%d",&x);
if(i!=) ans=M(ans+sum[i-]-w[x],MOD);
w[x]=M(w[x]+q[i-],MOD),ans=ans*;
}
printf("%lld\n",M(ans,MOD));
}
return ;
}
ZOJ 3929 Deque and Balls的更多相关文章
- 期望+DP ZOJ 3929 Deque and Balls
题目链接 题意:给你n个数,按照顺序依次放入一个双端队列(可放在头部,也可以放在尾部),求xi > xi+1的期望 * 2^n mod (1e9 +7) 分析:期望*2^n=出现这种排法的概率* ...
- ZOJ 3932 Deque and Balls
There are n balls, where the i-th ball is labeled as pi. You are going to put n balls into a deque. ...
- 【ZOJ 3929】Deque and Balls(普通dp)
题意:给出一个序列,按照顺序一个一个放入双端队列(可以放在头部也可以放在尾部),一个队列的美丽指数就是数列中a[i]>a[i+1]的个数,求美丽指数的期望*2^n的值. 解题思路:方便起见,我们 ...
- ZOJ-3929 Deque and Balls (DP+找规律)
题目大意:n个数,每个数的大小都在1~n之间.操作n次,第 i 次将第 i 个数放到一个双端队列里面,放到队列两端的概率是相等的.问操作n次之后双端队列中元素满足xi>xi+1的对数的期望,输出 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- 主席树[可持久化线段树](hdu 2665 Kth number、SP 10628 Count on a tree、ZOJ 2112 Dynamic Rankings、codeforces 813E Army Creation、codeforces960F:Pathwalks )
在今天三黑(恶意评分刷上去的那种)两紫的智推中,突然出现了P3834 [模板]可持久化线段树 1(主席树)就突然有了不详的预感2333 果然...然后我gg了!被大佬虐了! hdu 2665 Kth ...
- 整体二分(SP3946 K-th Number ZOJ 2112 Dynamic Rankings)
SP3946 K-th Number (/2和>>1不一样!!) #include <algorithm> #include <bitset> #include & ...
- ZOJ 2970 Faster, Higher, Stronger
F - Faster, Higher, Stronger Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld &am ...
- ZOJ 3279-Ants(线段树)
传送门:zoj 3279 Ants Ants Time Limit: 2 Seconds Memory Limit: 32768 KB echo is a curious and cleve ...
随机推荐
- servlet多次跳转报IllegalStateException异常
当发生在如下错误的时候,有一个方案可行, "java.lang.IllegalStateException: Cannot forward after response has been c ...
- 给Notepad++ 加带图标右键菜单
给Notepad++ 加带图标右键菜单 方式一: 拷贝以下代码建立一个reg文件,替换相关路径,保存,双击运行加入注册表 Windows Registry Editor Version 5.00 [H ...
- javascript语句语义大全(2)
1. 四则运算相关 +,-,*,/,% 分别是加减乘除和取余 2.Math.pow(a,b) a的b次方 3.toFixed(a) 四舍五入为指定小数位数的数字 4. k++; ++K 看似相同但是在 ...
- 用MyEclipse自动生成hibernate映射文件和实体类
创建数据库,创建相应的表 点击图标,选择MyEclipse Datebase Explorer 右击空白区域,选择new菜单,根据提示创建数据库连接,创建好后会显示你所创建的连接名,如图mysqldb ...
- HBase伪分布安装
1把hbase-0.94.2-security.tar.gz复制到/usr/local 2 解压缩.重命名.设置环境变量 cd /usr/local tar -zxvf hbase--security ...
- 提升html5的性能体验系列之五webview启动速度优化及事件顺序解析]
webview加载时有3个事件.触发顺序为loading.titleUpdate.loaded.webview开始载入页面时触发loading,载入过程中如果title已经解析并赋予新值,则触发tit ...
- jstat undocumented
jstat -J-Djstat.showUnsupported=true -name btrace.com.sun.btrace.samples.ThreadCounter.count 11674 h ...
- ms08_067利用过程
进入msf. show exploits. use exploit/windows/smb/ms08_067_netapi. show playloads. set PLAYLOAD windows/ ...
- PAT (Advanced Level) 1073. Scientific Notation (20)
简单模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- download plugin update site for offline installation
Reference Eclipse Launcher Running update manager from command line 好多次为window下的eclipse不能拿到linux下直 ...