当前位置:网站首页>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;
}
边栏推荐
- JS performs non empty judgment on various data types of the returned data.
- RANSAC提取圆柱(MATLAB内置函数)
- Work assessment of spectral analysis of Jilin University in March of the 22nd spring -00079
- [Part 16] copyonwritearraylist source code analysis and application details [key]
- Go language conditional statement
- 作为一名 ABAP 资深顾问,下一步可以选择哪一门 SAP 技术作为主攻方向?
- go语言的goto语句
- LeetCode-98-验证二叉搜索树
- JVM object allocation policy TLAB
- Diary at 16:29:41 on June 9, 2022
猜你喜欢

Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience

How to Load Data from CSV (Data Preparation Part)

Which Bluetooth headset is better within 500? Inventory of gifts for girls' Day

LabVIEW controls Arduino to realize ultrasonic ranging (advanced chapter-5)

Part I physical layer

The gateway starts other microservices first. When the gateway is started, the gateway cannot be started and there is no exception log; Start the gateway first, and all services can be started normall

LabVIEW控制Arduino实现超声波测距(进阶篇—5)

How to manually drag nodes in the Obsidian relationship graph

Goto statement of go language
![[Part 14] source code analysis and application details of completionservice class [key]](/img/41/9f5383d6eafb32723e29c15da3a1af.jpg)
[Part 14] source code analysis and application details of completionservice class [key]
随机推荐
如何创建最简单的 SAP Kyma Function
线性表的链式存储结构
RANSAC extract cylinder (matlab built-in function)
JUnit tests multithreaded code, and the sub thread does not run
The official announced the launch of Alibaba's 2023 global school recruitment: Technical Posts account for more than 60%
二分图King
Refresh and upgrade | innovation, starting from cloud store
Comprehensive RTL code design method and precautions
Serval and Rooted Tree(CF1153D)-DP
What are striplines and microstrip lines? Reference planes and transmission lines
Application business layer modification
Using the sap ui5 cli command line tool to build and run SAP ui5 applications
SQL的语法
成长的12条黄金法则
Codeforces Round #742 (Div. 2) F. One-Four Overload
select _ Lazy loading
Deploy SAP ui5 applications to the sap BTP kyma operating environment step by step
Cuckoo Hash
ASCII code comparison table
Part II data link layer