Manuel thinks that Diego is his long lost brother. But Diego thinks Manuel is wrong, and to prove it, he got DNA samples from himself and Manuel. Now Diego has given you the DNA samples and it is your task to say whether they are brothers or not.
The DNA samples of Diego and Manuel are strings A and B, both have length n (1≤n≤105) and consist of only the characters ‘A’, ‘T’, ‘G’ and ‘C’. If there is a common subsequence of A and B that has length greater than or equal to 0.99×n, then Diego and Manuel are brothers, in other case, they are not.
Input
The input consists of two lines with strings A and B, respectively.
Output
You should output a single line with “Long lost brothers D:” (without quotes) if Diego and Manuel are brothers, and “Not brothers 😦” (without quotes) if they are not.
Examples
Input
GAATTGCGTACAATGC
GAATTGCGTACAATGC
Output
Long lost brothers D:
Input
CCATAGAGAA
CGATAGAGAA
Output
Not brothers 😦
Note
A subsequence of a string X is any string that you can get by removing any number of characters from X.
A common subsequence of strings X and Y is a string that is a subsequence of both X and Y.
题目意思就是要求最长公共子序列,但是n比较大,如果用一般的求法,会T
#include <algorithm>
#include <cstring>
#include <iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const long long inff=0x3f3f3f3f3f3f3f3f;
const int maxn = 500050;
typedef long long ll;
string s1,s2;
int dp[1005][1005];
int main()
{
cin>>s1>>s2;
int t=s1.size(); //这里的s1,s2的长度相同,所以就一个t就行
int n=min(t,1000); //取小的
int m=min(t,1000);
int ans=0;
for(int i=0; i<=n; i++)
{
for(int j=0; j<=m; j++)
{
while(i+dp[i][j]<t&&j+dp[i][j]<t&&s1[i+dp[i][j]]==s2[j+dp[i][j]])dp[i][j]++;
dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
ans=max(dp[i][j],ans);
}
}
double q=ans*1.0/t; //ans就是最长的公共子序列
if(q>=0.99)
printf("Long lost brothers D:\n");
else printf("Not brothers :(\n");
return 0;
}