补多校系列,具体见多校题解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. fork开源代码后如何基于某个tag建立自己的branch

    应用场景: 在github上fork一个自己想看的开源项目,想基于某个tag来写一些测试demo,然后可以做到版本控制. 方法: //克隆 git clone xxxxx.git //查看tag gi ...

  2. 基于Thinkphp5+phpQuery 网络爬虫抓取数据接口,统一输出接口数据api

    TP5_Splider 一个基于Thinkphp5+phpQuery 网络爬虫抓取数据接口 统一输出接口数据api.适合正在学习Vue,AngularJs框架学习 开发demo,需要接口并保证接口不跨 ...

  3. 前端将markdown转换成html

    实现过程: 1. npm引入:npm install marked --save 2.在需要的文件(.ts)里import Marked from "marked";   如果.j ...

  4. QueryHelper插件类(hql)

    package cn.itcast.core.util; import java.util.ArrayList; import java.util.List; public class QueryHe ...

  5. 条件查询Criteria

    public User getUserByNameCri(String name){ Session session = null; User user = null; try { session = ...

  6. Python 日期时间相关

    #calendar日历模块 import calendar #calendar() 获取一年日历 result = calendar.calendar(2018,w = 2,l = 1,c = 6,m ...

  7. [Leetcode] unique paths 独特路径

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  8. Reasons to use innodb_file_per_table

    When working with InnoDB, you have two ways for managing the tablespace storage: Throw everything in ...

  9. CMU Bomblab 答案

    室友拉我做的... http://csapp.cs.cmu.edu/3e/labs.html Border relations with Canada have never been better. ...

  10. 转:Nginx国人开发缩略图模块(ngx_image_thumb)

    ngx_image_thumb是nginx中用来生成缩略图的模块,生存缩略图的方法很多,之前也写过一篇 <nginx生成缩略图配置>,在github上发现国人开发的一款模块,作者的文档写的 ...