Пример #1
0
        /// <summary>
        /// </summary>
        /// <param name="w1"></param>
        /// <param name="w2"></param>
        /// <returns>
        /// dp[i, j, k] : w1のi文字目とw2のj文字目を最後に使い, k回飛ばした時の最大一致度
        /// k <= 1
        /// </returns>
        public void DoDP(IWord w1, IWord w2, out double[,,] dp)
        {
            List <Sound> sounds1 = dissassemble(w1.ToRoma());
            List <Sound> sounds2 = dissassemble(w2.ToRoma());
            int          n = sounds1.Count, m = sounds2.Count;

            dp = new double[n + 1, m + 1, 2];
            if (n == 0 || m == 0)
            {
                return;
            }
            for (int i = 0; i < n + 1; i++)
            {
                for (int j = 0; j < m + 1; j++)
                {
                    dp[i, j, 1] = -1e10;
                    if (i == 0 || j == 0)
                    {
                        continue;
                    }
                    dp[i, j, 0] = -1e10;
                }
            }
            for (int i = 0; i < n + 1; i++)
            {
                for (int j = 0; j < m + 1; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        if (i < n && j < m)
                        {
                            dp[i + 1, j + 1, k] = Math.Max(
                                dp[i + 1, j + 1, k],
                                dp[i, j, k] + compareSound(sounds1[i], sounds2[j])
                                );
                        }
                        if (k == 1)
                        {
                            continue;
                        }
                        if (i < n)
                        {
                            dp[i + 1, j, k + 1] = Math.Max(dp[i + 1, j, k + 1], dp[i, j, k] - 2);
                        }
                        if (j < m)
                        {
                            dp[i, j + 1, k + 1] = Math.Max(dp[i, j + 1, k + 1], dp[i, j, k] - 2);
                        }
                    }
                }
            }
            return;
        }
Пример #2
0
 public string ToRoma()
 {
     return(_word.ToRoma());
 }