-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathDistinct_Occurences.cpp
More file actions
39 lines (38 loc) · 901 Bytes
/
Distinct_Occurences.cpp
File metadata and controls
39 lines (38 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<bits/stdc++.h>
using namespace std;
int Count_All_Distinct_Occurences(string s1,string s2){
int n=s1.length(),m=s2.length();
if(m>n) return 0;
int dp[n+1][m+1];
for(int i=0;i<=m;i++) dp[0][i]=0;
for(int i=0;i<=n;i++) dp[i][0]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(s1[i-1]==s2[j-1]){
dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
}
else{
dp[i][j] = dp[i-1][j];
}
}
}
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
cout<<dp[i][j]<<" ";
}
cout<<"\n";
}
return dp[n][m];
}
int main(){
int t;
cin>>t;
while(t--){
string s1,s2;
cin>>s1>>s2;
cout<<Count_All_Distinct_Occurences(s1,s2)<<"\n";
}
}
//s1=banana
//s2=ban
//therefore count=3 ie 3 distinct susequence of s2 occurs in s1;