Nowcoder 5.D 子序列 组合数学
来源:互联网 发布:果冻手表淘宝 编辑:程序博客网 时间:2024/06/05 03:14
题意:给出字符串T,问有多少个长度为m的字符串S满足,T是S的子序列.
|T|,m<=1e5.
设d[i]:[1...i]时,字符串T第一次作为子序列出现
d[i]= (C(i-1,t-1)*pw[i-t]) - (d[i-1]+d[i-2]+..d[1]). 前半部分明显计算重复!!!(然后就卡在这里了..).
换种思考方式,m个位置 假如当前匹配了i位 那么匹配到下一位之前 每个位置都是只有25种选法.最后匹配到第x位结束.后面位任意
|T|,m<=1e5.
设d[i]:[1...i]时,字符串T第一次作为子序列出现
d[i]= (C(i-1,t-1)*pw[i-t]) - (d[i-1]+d[i-2]+..d[1]). 前半部分明显计算重复!!!(然后就卡在这里了..).
换种思考方式,m个位置 假如当前匹配了i位 那么匹配到下一位之前 每个位置都是只有25种选法.最后匹配到第x位结束.后面位任意
还是枚举第一次匹配成功的位置i,前面i-1个位置选t-1个作为匹配位.剩下的每个位置都有25种选法.
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N=2e5+5,mod=1e9+7;ll pw[N],d[N],f[N],T,m,pw25[N];void init(){f[0]=pw[0]=pw25[0]=1;for(ll i=1;i<N;i++)pw25[i]=(pw25[i-1]*25ll)%mod,f[i]=(f[i-1]*i)%mod,pw[i]=(pw[i-1]*26ll)%mod;} ll powmod(ll x,ll n){ll s=1;while(n){if(n&1)s=(s*x)%mod;x=(x*x)%mod;n>>=1;}return s;}ll C(ll n,ll m){if(n<m)return 0;ll a=f[n],b=(f[m]*f[n-m])%mod;return (a*powmod(b,mod-2))%mod;}char s[N];ll cnt[30];int main(){init();scanf("%s%I64d",s,&m);ll t=strlen(s);ll ans=0,pre=0;for(ll i=t;i<=m;i++){d[i]=(C(i-1,t-1)*pw25[i-t]+mod)%mod;pre=(pre+d[i])%mod;ans=(ans+(d[i]*pw[m-i])%mod)%mod;//cout<<i<<' '<<d[i]<<endl;}cout<<ans<<endl;return 0;}
阅读全文
0 0
- Nowcoder 5.D 子序列 组合数学
- Wannafly挑战赛5 D.子序列 组合数学
- 51nod 1202 子序列个数 (组合数学 +动态规划)
- Codeforces-785D (组合数学)
- nowcoder->翻转子串
- NowCoder-包含一(数学)
- Codeforces 615D Multipliers 【组合数学】
- codeforces 900D(组合数学+剪枝)
- CodeForces 26 D.Tickets(组合数学)
- 4403: 序列统计 组合数学+Lucas定理
- Bzoj4403序列统计:Lucas初探,组合数学
- [组合数学] BZOJ 4403 序列统计
- bzoj4403 序列统计 ( 组合数学 + lucas )
- 博弈论 NIM取子问题 组合数学
- C语言实现 组合数学 生成组合序列
- 【hpu oj 1011 QAQ的序列组合 [组合数学]】
- Codeforces 895D Round#448 2D :组合数学+小学数学优化
- 组合数学:D - Cellular Automaton 求矩阵相乘
- 蒟蒻与有上下界网络流的约会
- c语言基础04
- 公众号文章禁止转载,php开发微信公众号,禁止分享和复制
- [解读] Brocade(博科)为何认为FC是NVMe over Fabric中最好的Fabric?
- 老男孩教育Linux Shell高级编程实战视频教程完整14部分
- Nowcoder 5.D 子序列 组合数学
- skyline查询——bitmap算法
- uva 10375 Choose and divide
- 杂书笔记
- 定积分的基本性质1 线性性质
- JDK自带锁ReentrantLock
- 关于eclipse的svn内容冲突
- BufferedOutputStream与BufferedInputStream
- 从今天起让我们忘记Java中的get/set方法吧!