UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212094#3816. 元素PanjunnanCompile Error//C++1.0kb2024-10-13 11:10:312024-10-13 12:22:11

answer

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int minTimeToWrite(string S, string T) {
    int n = S.size();
    int m = T.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, -1));

    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        dp[i][0] = i;
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (S[i - 1] == T[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = dp[i - 1][j] + 1; 
                for (int k = 1; k < i; ++k) {
                    if (S[k - 1] == T[j - 1]) {
                        dp[i][j] = min(dp[i][j], dp[k][j] + abs(k - i));
                    }
                }
            }
        }
    }

    return dp[n][m];
}

int main() {
    int n, m;
    cin >> n >> m;
    string S, T;
    cin >> S >> T;

    int result = minTimeToWrite(S, T);
    cout << result << endl;

    return 0;
}

详细

answer.code: In function 'int minTimeToWrite(std::string, std::string)':
answer.code:11:22: error: '>>' should be '> >' within a nested template argument list
     vector<vector<int>> dp(n + 1, vector<int>(m + 1, -1));\x0d
                      ^