示例#1
0
        public override void CreateSamples(StreamReader reader)
        {
            CommonChildSample sample = new CommonChildSample()
            {
                s1 = reader.ReadLine(), s2 = reader.ReadLine()
            };

            Samples.Add(sample);
        }
示例#2
0
        //[SolutionMethod]
        public CommonChildAnswer BF(CommonChildSample sample)
        {
            Int32  result = 0;
            String s1     = sample.s1;
            String s2     = sample.s2;

            result = CheckStr(s1, 0, s2, 0);

            return(new CommonChildAnswer()
            {
                result = result
            });
        }
示例#3
0
        public TAnswer DP(TSample Sample)
        {
            CommonChildSample sample = Sample as CommonChildSample;

            Int32  result = 0;
            String s1     = sample.s1;
            String s2     = sample.s2;

            Int32[,] DP = new Int32[s1.Length + 1, s2.Length + 1];

            /*
             * Console.WriteLine();
             * for (int i = 0; i < s1.Length; i++)
             * {
             *  String str = i.ToString().PadLeft(2);
             *  Console.Write($"{str} ");
             * }
             *
             * Console.WriteLine();
             */

            for (int i = 0; i < s1.Length; i++)
            {
                for (int j = 0; j < s2.Length; j++)
                {
                    if (s1[i] == s2[j])
                    {
                        DP[i, j] = 1;
                    }
                }
            }

            for (int j = s2.Length - 1; j >= 0; j--)
            {
                for (int i = s1.Length - 1; i >= 0; i--)
                {
                    Int32 M = Math.Max(DP[i + 1, j], DP[i + 1, j + 1] + DP[i, j]);
                    M = Math.Max(M, DP[i, j + 1]);
                    //DP[i, j] = Math.Max(DP[i+1,j], DP[i+1, j+1]+ DP[i,j]);
                    DP[i, j] = M;
                    if (DP[i, j] > result)
                    {
                        result = DP[i, j];
                    }
                }

                /*
                 * for (int i = 0; i < s1.Length; i++)
                 * {
                 *  Console.Write($"{DP[i, j].ToString().PadLeft(2)} ");
                 * }
                 * Console.WriteLine();
                 */
            }


            /*
             * for (int i = 0; i < s1.Length; i++)
             * {
             *  if (DP[i, s2.Length] > result)
             *  {
             *      result = DP[s1.Length-1, i];
             *  }
             * }
             */


            return(new CommonChildAnswer()
            {
                result = result
            });
        }