ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212114 | #3817. 写字 | Panjunnan | Compile Error | / | / | C++ | 1.2kb | 2024-10-13 11:18:58 | 2024-10-13 12:24:04 |
answer
#include <iostream>
#include <vector>
#include <string>
#include <climits>
using namespace std;
int minTimeToGenerateT(const string& S, const string& T) {
int n = S.size();
int m = T.size();
vector<vector<int> > dp(n + 1, vector<int>(m + 1, INT_MAX));
dp[0][0] = 0;
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= m; ++j) {
if (i == 0 && j == 0) continue;
if (i == 0 || j == 0) {
dp[i][j] = INT_MAX;
continue;
}
if (S[i - 1] == T[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
for (int k = 0; k < i; ++k) {
if (S[k] == T[j - 1]) {
dp[i][j] = min(dp[i][j], dp[k][j - 1] + abs(i - k));
}
}
}
}
}
return dp[n][m] == INT_MAX ? -1 : dp[n][m];
}
int main() {
int n, m;
cin >> n >> m;
string S, T;
cin >> S >> T;
int result = minTimeToGenerateT(S, T);
cout << result << endl;
return 0;
}
Details
answer.code: In function 'int minTimeToGenerateT(const string&, const string&)': answer.code:32:74: error: 'abs' was not declared in this scope dp[i][j] = min(dp[i][j], dp[k][j - 1] + abs(i - k));\x0d ^