当前位置:网站首页>2021 Niuke multi school 5 double strings
2021 Niuke multi school 5 double strings
2022-06-11 21:24:00 【dplovetree】
Double Strings
The question :
Here are two strings s s s and t t t, The length is less than or equal to 5000, Find out how many seed sequences there are , bring s and t The length of the subsequence is the same , however s s s The lexicographic order ratio of a string composed of subsequences of t t t Small .
Ideas :
The dictionary order is small , That is, the parts with the same prefix , There is a little dictionary order , Then just take the same length .
We can use dp[ i i i] [ j j j], To preprocess out , s s s Before i i i position , and t t t Before j j j position , The number of schemes with the same prefix .
The transfer equation is :
dp[ i i i] [ j j j] = dp[ i i i - 1] [ j j j] + dp [ i i i] [ j j j - 1] - dp[ i i i - 1] [ j j j - 1];
Like the transfer equation of the longest common subsequence , Add the previous cases and subtract the repeated parts .
When s[ i i i] == t[ j j j] when ,dp[ i i i] [ j j j] = dp[ i i i - 1] [ j j j - 1] + 1;
Now how to find Any suffix of the same length , We assume that s s s The remaining length in is x x x, t t t Remaining length bits in y y y, set up x x x<= y y y, Then find any suffix with the same length , Namely s s s and t t t Take i i i individual ( i i i Maximum to x x x), Yes :
The last step of transformation uses van der Monde's convolution formula .
And then it's fun AC 了 .
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=100010,INF=1e9;
const ll mod=1e9+7;
ll qp(ll n,ll m){
ll ans=1;
while(m){
if(m%2==1)ans=ans*n%mod;
n=n*n%mod;
m/=2;
}
return ans;
}
ll n,m;
ll dp[5005][5005];
ll fac[10004];
ll inv[10004];
void init(){
fac[1]=1;fac[0]=1;
for(int i=2;i<=10000;i++)fac[i]=fac[i-1]*i%mod;
inv[10000]=qp(fac[10000],mod-2)%mod;
for(int i=9999;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
}
ll C(int n,int m){
if(n<m)return 0;
else {
return fac[n]*inv[n-m]%mod*inv[m]%mod;
}
}
char s[5005],t[5004];
int main(){
init();
scanf("%s%s",s+1,t+1);
int len1=strlen(s+1),len2=strlen(t+1);
for(int i=1;i<=len1;i++){
for(int j=1;j<=len2;j++){
dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
dp[i][j]%=mod;
if(s[i]==t[j]){
dp[i][j]+=dp[i-1][j-1]+1;
}
dp[i][j]=(dp[i][j]%mod+mod)%mod;
}
}
ll ans=0;
for(int i=1;i<=len1;i++){
for(int j=1;j<=len2;j++){
if(s[i]<t[j]){
ans=(ans+(dp[i-1][j-1]+1)%mod*C(len1-i+len2-j,len1-i)%mod)%mod;
}
}
}
printf("%lld\n",ans);
return 0;
}
边栏推荐
- Codeforces Round #742 (Div. 2) F. One-Four Overload
- Only 38 years old! Zhou Chuan, a researcher of the Chinese Academy of Sciences, died unfortunately. Rao Yi sent a document to mourn: he guided me when he was still my student
- ORA-04098: trigger ‘xxx. xxx‘ is invalid and failed re-validation
- UML系列文章(29)体系结构建模---模式和框架
- JVM|本地方法接口;本地方法栈
- Diary at 16:29:41 on June 9, 2022
- Answer fans' questions | count the number and frequency of letters in the text
- 第二部分 数据链路层
- RANSAC extract cylinder (matlab built-in function)
- LeetCode-43-字符串相乘
猜你喜欢
![[advanced C language] integer storage in memory](/img/a5/6c7df3b8f427fe724922a6b853516f.png)
[advanced C language] integer storage in memory

Apache local multi port configuration

My collection of scientific research websites

JMeter load test finds the maximum number of concurrent users (including step analysis)

LeetCode-129-求根节点到叶节点数字之和

Three waves of changes in cloud computing

SQL的语法

Explanation of each column output by explain statement

JVM object allocation policy TLAB

Why is your LDO output unstable?
随机推荐
JVM之对象创建过程
RANSAC extract cylinder (matlab built-in function)
杭电中超9 1006 Guess the Weight
My collection of scientific research websites
Test plans and test cases
select _ Lazy loading
Three waves of changes in cloud computing
Goto statement of go language
Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
使用 SAP UI5 CLI 命令行工具构建和运行 SAP UI5 应用
【博弈论-绪论】
Comprehensive RTL code design method and precautions
Go语言函数
从概率论基础出发推导卡尔曼滤波
Regular check matches positive integer or decimal limit between [0-100] and [0-1000]
俩月没发过博客了,发一篇证明自己的账号还活着
JVM object allocation policy TLAB
【博弈论-完全信息静态博弈】 战略式博弈
2021牛客多校5 Double Strings
RANSAC提取圆柱(MATLAB内置函数)