补多校系列,具体见多校题解http://www.cnblogs.com/duoxiao/p/5777700.html

值得注意的是如果当前i初始向左,前i个骑士最终只有1个向右

对于f[i][1]状态的转移为f[i][1]=∑ f[i-1][k]*0.5^(k-1)

因为我们只要比k-1场就可以了,那一个活下来的是骑士i还是前i-1个骑士中的无关紧要

 #include<bits/stdc++.h>

 using namespace std;
typedef long long ll;
const int mo=1e9+;
ll f[][],d[];
int a[],n; ll quick(ll x,int y)
{
ll s=;
while (y)
{
if (y&) s=s*x%mo;
x=x*x%mo;
y>>=;
}
return s;
} int main()
{
int cas;
scanf("%d",&cas);
d[]=; d[]=quick(,mo-);
for (int i=; i<=; i++) d[i]=d[i-]*d[]%mo;
for (int tt=; tt<=cas; tt++)
{
scanf("%d",&n);
for (int i=; i<=n; i++) scanf("%d",&a[i]);
printf("Case #%d: ",tt);
if (n==)
{
puts("");
continue;
}
memset(f,,sizeof(f));
f[][]=;
for (int i=; i<n; i++)
if (a[i])
{
for (int j=; j<=i; j++)
f[i][j]=f[i-][j-];
}
else {
for (int j=i-; j>=; j--)
f[i][j]=(f[i-][j]+f[i][j+])*d[]%mo;
for (int j=; j<=i-; j++)
f[i][]=(f[i][]+f[i-][j]*d[j-]%mo)%mo;
}
ll ans=;
for (int i=; i<n; i++)
ans=(ans+f[n-][i]*d[i]%mo)%mo;
printf("%lld\n",ans);
}
}

hdu5819的更多相关文章

随机推荐

  1. [Elasticsearch] 多字段搜索 (二) - 最佳字段查询及其调优(转)

    最佳字段(Best Fields) 假设我们有一个让用户搜索博客文章的网站,就像这两份文档一样: PUT /my_index/my_type/1 { "title": " ...

  2. 在vue-cli创建的项目里配置scss

    第一步,gitbash进入到项目目录 npm install node-sass --save-dev npm install sass-loader --save-dev 第二步:打开webpack ...

  3. java高精度类尝试

    java高精度尝试, poj2109,比较坑的题目 import java.io.*; import java.util.*; import java.math.*; public class Mai ...

  4. [HAOI2010]计数

    题面在这里 description 你有一组非零数字(不一定唯一),你可以在其中插入任意个0,这样就可以产生无限个数. 比如说给定{1,2},那么可以生成数字12,21,102,120,201,210 ...

  5. 周记【距gdoi:110天】

    这两个星期都在复习和考试,进度慢了好多.(考试也觉得似乎不是很理想) 姚老要我们写个程序来应对学校的分班问题.然后我们就脑洞打开准备设计一个.写应用程序应该是很烧时间的吧? 接下来搞搞后缀数组,然后还 ...

  6. [Leetcode] Balanced binary tree平衡二叉树

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...

  7. BZOJ4012 [HNOI2015]开店 【动态点分治 + splay】

    题目链接 BZOJ4012 题解 Mychael并没有A掉,而是T掉了 讲讲主要思路 在点分树上每个点开两棵\(splay\), 平衡树\(A\)维护子树中各年龄到根的距离 平衡树\(B\)维护子树中 ...

  8. BZOJ1982 [Spoj 2021]Moving Pebbles 【博弈论】

    题目 Moving Pebbles Two players play the following game. At the beginning of the game they start with ...

  9. HDU1151:Air Raid(最小边覆盖)

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  10. Terminals Project

    https://github.com/Terminals-Origin Terminals Project Terminals is a secure, multi tab terminal serv ...