alt

int max(int a,int b){
    return a>b?a:b;
}

char* LCS(char* s1, char* s2 ) {
    int len1=strlen(s1);
    int len2=strlen(s2);
    if(len1==0||len2==0){
        return "-1";
    }
    int** dp=(int**)malloc(sizeof(int*)*len1+1);
    for(int i=0;i<len1+1;i++){
        dp[i]=(int*)malloc(sizeof(int)*len2+1);
        dp[i][0]=0;
    }
    for(int i=0;i<len2+1;i++){
        dp[0][i]=0;
    }
    int i;
    int j;
    for(i=1;i<len1+1;i++){
        for(j=1;j<len2+1;j++){
            if(s1[i-1]==s2[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }else if(s1[i-1]!=s2[j-1]){
                dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
            }
        }
    }
//     printf("%d",dp[len1][len2]);
//     printf("%d",dp[1][2]);
    int LCS_len=dp[len1][len2];
    
    if(LCS_len==0){
        return "-1";
    }
    
    char* res=(char*)malloc(sizeof(char)*(LCS_len+1));
    res[LCS_len--]='\0';
    i--;
    j--;
    while(i!=0&&j!=0){
        if(dp[i][j]>dp[i][j-1]&&dp[i][j]>dp[i-1][j]){
            res[LCS_len--]=s1[i-1];
            i--;
            j--;
        }else if(dp[i][j]==dp[i][j-1]&&dp[i][j]>dp[i-1][j]){
            j--;
        }else if(dp[i][j]>dp[i][j-1]&&dp[i][j]==dp[i-1][j]){
            i--;
        }else{
            i--;
            j--;
        }
    }
    return res;
}