KY114 Coincidence

最长非连续子串长度,自己扣了半天,没写准,看了题解恍然大明白
ti

#include

using namespace std;

int n, m, c;
int p[1000010], q[1000010], k[2000010];
string s1, s2;
map<char, int>mp;
int dp[110][110]; 
int d[110]; 

bool cpdd(char a, char b){
	if(a == b) return 1;
	return 0;
}

int main() {
    while (cin >> s1 >> s2) {  //非连续最长公共子序列 
    	memset(dp, 0, sizeof dp);
    	int len1 = s1.length();
    	int len2 = s2.length();
    	
		for(int i = 1; i <= len1; i ++ ){
			for(int j = 1; j <= len2; j ++ ){
				if(s1[i - 1] == s2[j - 1]){
					dp[i][j] = dp[i - 1][j - 1] + 1;
				}
				else{
					dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
				}
			}
		} 
        
        cout<< dp[len1][len2] << endl;
    }
    return 0;
}

你可能感兴趣的:(算法)