2018.12.12 codeforces 935D. Fafa and Ancient Alphabet(概率dp)
传送门
概率dp水题。
题意简述:给你数字表的大小和两个数列,数列中为0的数表示不确定,不为0的表示确定的,求第一个数列字典序比第二个数列大的概率。
fif_ifi表示第i ni~ ni n位第一个数列比第二个数列大的概率。
然后分是否为0的情况讨论一下就行了。
代码:
#include<bits/stdc++.h>
#define ri register int
using namespace std;
inline int read(){
int ans=0;
char ch=getchar();
while(!isdigit(ch))ch=getchar();
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
return ans;
}
const int mod=1e9+7,N=1e5+5;
typedef long long ll;
int n,m,f[N],a[N],b[N],add,inv;
inline int ksm(int a,int p){int ret=1;for(;p;p>>=1,a=(ll)a*a%mod)if(p&1)ret=(ll)ret*a%mod;return ret;}
inline int calc(int a,int b){return (ll)a*ksm(b,mod-2)%mod;}
int main(){
freopen("lx.in","r",stdin);
n=read(),m=read(),add=(ll)m*(m-1)/2%mod,inv=ksm(m,mod-2);
for(ri i=1;i<=n;++i)a[i]=read();
for(ri i=1;i<=n;++i)b[i]=read();
for(ri i=n;i;--i){
if(a[i]&&b[i])f[i]=a[i]==b[i]?f[i+1]:(a[i]>b[i]?1:0);
else if(a[i])f[i]=(ll)(a[i]-1+f[i+1])*inv%mod;
else if(b[i])f[i]=(ll)(m-b[i]+f[i+1])*inv%mod;
else f[i]=(ll)(add+(ll)m*f[i+1]%mod)*inv%mod*inv%mod;
}
cout<<f[1];
return 0;
}
2018.12.12 codeforces 935D. Fafa and Ancient Alphabet(概率dp)的更多相关文章
- Codeforces 935D Fafa and Ancient Alphabet
题目链接 题意 给定两个\(n\)位的\(m\)进制数\(s1,s2\),所有出现的\(0\)均可等概率地被其他数字替换,求\(s1\gt s2\)的概率. 思路 从高位到低位,根据每一位上相应的\( ...
- CodeForces 935E Fafa and Ancient Mathematics (树形DP)
题意:给定一个表达式,然后让你添加 n 个加号,m 个减号,使得表达式的值最大. 析:首先先要建立一个表达式树,这个应该很好建立,就不说了,dp[u][i][0] 表示 u 这个部分表达式,添加 i ...
- Codeforces 935E Fafa and Ancient Mathematics dp
Fafa and Ancient Mathematics 转换成树上问题dp一下. #include<bits/stdc++.h> #define LL long long #define ...
- Codeforces B. Bad Luck Island(概率dp)
题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces 678E. Another Sith Tournament(概率DP,状压)
Codeforces 678E. Another Sith Tournament 题意: n(n<=18)个人打擂台赛,给定任意两人对决的胜负概率,比赛规则:可指定一人作为最开始的擂主,每次可指 ...
- 2018.12.12 codeforces 931E. Game with String(概率dp)
传送门 感觉这题难点在读懂题. 题目简述:给你一个字符串s,设将其向左平移k个单位之后的字符串为t,现在告诉你t的第一个字符,然后你可以另外得知t的任意一个字符,求用最优策略猜对k的概率. 解析: 预 ...
- Codeforces 935E Fafa and Ancient Mathematics(表达式转树 + 树型DP)
题目链接 Codeforces Round #465 (Div. 2) Problem E 题意 给定一个表达式,然后用$P$个加号和$M$个减号填充所有的问号(保证问号个数等于$P + M$) ...
- codeforce465DIV2——D. Fafa and Ancient Alphabet
概率的计算答案给出的这张图很清楚了,然后因为要求取模,a/b%M=a*b^-1%M=a*inv(b,M)%M; #include <cstdio> #include <cstring ...
- 【学术篇】CF935E Fafa and Ancient Mathematics 树形dp
前言 这是一道cf的比赛题.. 比赛的时候C题因为自己加了一个很显然不对的特判WA了7次但找不出原因就弃疗了... 然后就想划水, 但是只做了AB又不太好... 估计rating会掉惨 (然而事实证明 ...
随机推荐
- 关于set_output_delay与set_input_delay概念与用法
一. 这两条约束语句都是针对板级延时而言的. 语句中必须的有是,时钟与port. 二. set_input_delay 用于数据输入端口,调节数据输入与时钟输入到来的相位关系. 当FPGA外部送 ...
- 微信小程序开发——连续快速点击按钮调用小程序api返回后仍然自动重新调用的异常处理
前言: 小程序开发中诸如获取用户手机号码.调起微信支付.领取卡券等api都是会有一定的延迟的.也就是说通过点击按钮调用这些api的时候,从点击按钮调用api,到支付页面或者领取卡券界面展示出来是需要一 ...
- 23【notepad++】修改背景颜色
notepad++是一款功能丰富的编辑器,运行在windows平台上的编辑工具. 但它默认设置是白色背景,黑色文字,长时间看很刺眼.那么怎么设定成为暗色背景,亮色文字呢? 点击,设置->语言格式 ...
- classpath分析
1. 什么是classpath? classpath相当于Java执行环境,它指定了一些常用的包或jar的位置,方便我们对项目文件的使用,而不必重复多次写所需要文件的位置. 在classpath ...
- 弹框alertView
// 创建一个弹框UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@“标题” message:@“显示的具体内容” delegate:s ...
- java ASM动态生成类
BeanTest2.java import java.io.FileOutputStream; import org.objectweb.asm.AnnotationVisitor; import o ...
- PAT 1021 个位数统计 (15)(C++&Java&Python)
1021 个位数统计 (15)(15 分) 给定一个k位整数N = d~k-1~*10^k-1^ + ... + d~1~*10^1^ + d~0~ (0<=d~i~<=9, i=0,.. ...
- BZOJ3191或洛谷2059 [JLOI2013]卡牌游戏
BZOJ原题链接 洛谷原题链接 我们可以倒着来\(DP\). 设\(f[i][j]\)表示剩余\(i\)个人,从庄家数起第\(j\)个人的胜率,设当前枚举到第\(k\)张牌,该情况下这一轮淘汰的位置为 ...
- Codeforces 782C. Andryusha and Colored Balloons 搜索
C. Andryusha and Colored Balloons time limit per test:2 seconds memory limit per test:256 megabytes ...
- Carbon document
< Getting Started Docs Reference History Contribute Github Introduction The Carbon class is inh ...