csp-j T24
  • 板块学术版
  • 楼主chaynflow
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/9/16 19:18
  • 上次更新2023/11/2 20:03:31
查看原帖
csp-j T24
559665
chaynflow楼主2023/9/16 19:18
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int f(string x, string y) {
    int m = x.size();
    int n = y.size();
    vector< vector<int> > v(m+1,vector<int>(n+1,0));
    for(int i = 1; i <= m; i++) {
        for(int j = 1; j <= n; j++) {
            if(x[i-1] == y[j-1]) {
                v[i][j] = v[i-1][j-1] + 1;
            } else {
              v[i][j] = max(v[i-1][j], v[i][j-1]);
        }}
    }
    return v[n][m]; // 已修改
}

bool g(string x, string y) {
    if(x.size() != y.size()) {
        return false;
    }
    return (f(x + x, y) == y.size());
}

int main() {
    string x, y;
    cin >> x >> y;
    cout << g(x, y) << endl;
    return 0;
}

采用洛谷 ide c++14 运行:

input:

aabb abab

output:

0

经测试,较大数据也可以正常运行,所以答案是否可能是 B?

单纯想问,请不要以分数来说。

2023/9/16 19:18
加载中...