답안 #97466

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97466 2019-02-16T11:06:21 Z Kastanda 원형 문자열 (IZhO13_rowords) C++11
컴파일 오류
0 ms 0 KB
// I do it for the glory
#include<bits/stdc++.h>
using namespace std;
const int N = 2009, NN = N * 2;
int n, m, dp[NN][N], P[NN][N];
char A[NN], B[N];
inline int RLCS()
{
    int Mx = 0;n
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            dp[i][j] = max({dp[i-1][j], dp[i][j-1], dp[i-1][j-1] + (A[i] == B[j])});
            if (dp[i][j] == dp[i][j - 1])
                P[i][j] = 2;
            else if (A[i] == B[j] && dp[i][j] == dp[i - 1][j - 1] + 1)
                P[i][j] = 1;
            else
                P[i][j] = 0;
        }
    Mx = dp[n][m];

    for (int i = n + 1; i <= n + n; i++)
    {
        /* **** Deleting the first row **** */

        int last = i - n, nw = 0;
        for (int j = 1; j <= m; j++)
        {
            if (last != i && P[last][j] != 2)
            {
                P[last][j] = 2;
                last ++;
                while (last < i && P[last][j] == 0)
                    P[last][j] = 2, last ++;
            }
            if (last == i)
                dp[i - 1][j] --;
        }

        /* **** Adding the last row **** */

        for (int j = 1; j <= m; j++)
        {
            dp[i][j] = max({dp[i-1][j], dp[i][j-1], dp[i-1][j-1] + (A[i] == B[j])});
            if (dp[i][j] == dp[i][j - 1])
                P[i][j] = 2;
            else if (A[i] == B[j] && dp[i][j] == dp[i - 1][j - 1] + 1)
                P[i][j] = 1;
            else
                P[i][j] = 0;
        }

        Mx = max(Mx, dp[i][m]);
    }
    return (Mx);
}
int main()
{
    scanf("%s%s", A + 1, B + 1);
    n = strlen(A + 1);
    m = strlen(B + 1);
    memcpy(A + n + 1, A + 1, n);
    int Mx = RLCS();
    reverse(B + 1, B + m + 1);
    return !printf("%d\n", max(Mx, RLCS()));
}

Compilation message

rowords.cpp: In function 'int RLCS()':
rowords.cpp:10:5: error: expected ';' before 'memset'
     memset(dp, 0, sizeof(dp));
     ^~~~~~
rowords.cpp:10:30: warning: statement has no effect [-Wunused-value]
     memset(dp, 0, sizeof(dp));
                              ^
rowords.cpp:28:27: warning: unused variable 'nw' [-Wunused-variable]
         int last = i - n, nw = 0;
                           ^~
rowords.cpp: In function 'int main()':
rowords.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s%s", A + 1, B + 1);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~