Ejemplo n.º 1
0
    // Driver Function
    public static void main(String[] args)
    {
        int[] arr1  = { 10, 15, 20, 25, 30, 35, 40 };
        int[] arr2  = { 10, 12, 23, 25, 28, 30, 32, 40 };
        int   size1 = arr1.Length;
        int   size2 = arr2.Length;
        LCS   obj   = new LCS();
        int   l     = obj.LongestCommonSubsequence(arr1, arr2, size1, size2);

        System.Write("Length of Longest Common Subsequence is: " + l);
    }
Ejemplo n.º 2
0
            public static OResult <T> GetLongCommSubseq <T>(Tuple <T, int>[] prot1_resn_resi, Tuple <T, int>[] prot2_resn_resi)
            {
                var lcs = LCS.LongestCommonSubsequence(prot1_resn_resi, prot2_resn_resi, Equals);

                T  [] lcs_resn  = new T  [lcs.Length];
                int[] lcs_resi1 = new int[lcs.Length];
                int[] lcs_resi2 = new int[lcs.Length];
                int[] lcs_idx1  = new int[lcs.Length];
                int[] lcs_idx2  = new int[lcs.Length];
                for (int i = 0; i < lcs.Length; i++)
                {
                    T   resn  = lcs.lcs[i].Item1;
                    int idx1  = lcs.lcsidx1[i];
                    int idx2  = lcs.lcsidx2[i];
                    int resi1 = prot1_resn_resi[idx1].Item2;
                    int resi2 = prot2_resn_resi[idx2].Item2;
                    if (HDebug.IsDebuggerAttached)
                    {
                        bool check1 = (dynamic)resn == prot1_resn_resi[idx1].Item1;
                        bool check2 = (dynamic)resn == prot2_resn_resi[idx2].Item1;
                        HDebug.Assert(check1 && check2);
                    }

                    lcs_resn [i] = resn;
                    lcs_resi1[i] = resi1;
                    lcs_resi2[i] = resi2;
                    lcs_idx1 [i] = idx1;
                    lcs_idx2 [i] = idx2;
                }
                Tuple <LCS.Oper, T, int?>[] lcs_oper1to2 = new Tuple <LCS.Oper, T, int?> [lcs.oper1to2.Length];
                for (int i = 0; i < lcs.oper1to2.Length; i++)
                {
                    LCS.Oper oper = lcs.oper1to2[i].Item1;
                    T        resn = lcs.oper1to2[i].Item2.Item1;
                    int?     resi = lcs.oper1to2[i].Item2.Item2;
                    if (oper == LCS.Oper.Insert)
                    {
                        resi = null;
                    }
                    lcs_oper1to2[i] = new Tuple <LCS.Oper, T, int?>(oper, resn, resi);
                }
                Tuple <LCS.Oper, T, int?>[] lcs_oper2to1 = new Tuple <LCS.Oper, T, int?> [lcs.oper2to1.Length];
                for (int i = 0; i < lcs.oper2to1.Length; i++)
                {
                    LCS.Oper oper = lcs.oper2to1[i].Item1;
                    T        resn = lcs.oper2to1[i].Item2.Item1;
                    int?     resi = lcs.oper2to1[i].Item2.Item2;
                    if (oper == LCS.Oper.Insert)
                    {
                        resi = null;
                    }
                    lcs_oper2to1[i] = new Tuple <LCS.Oper, T, int?>(oper, resn, resi);
                }

                return(new OResult <T>
                {
                    prot1_resn_resi = prot1_resn_resi,
                    prot2_resn_resi = prot2_resn_resi,
                    lcs_resn = lcs_resn,
                    lcs_resi1 = lcs_resi1,
                    lcs_resi2 = lcs_resi2,
                    lcs_idx1 = lcs_idx1,
                    lcs_idx2 = lcs_idx2,
                    lcs_oper1to2 = lcs_oper1to2,
                    lcs_oper2to1 = lcs_oper2to1,
                });
            }