60分智障代码在线求调
查看原帖
60分智障代码在线求调
326172
Wuming_Shi楼主2023/12/26 16:10
#include <bits/stdc++.h>
using namespace std;

int part, dp[1000][1000], maxlen;
string ss;
set<string> wordlst;

#define F(x, a, b) for (auto x = a; x <= b; x++)

int main() {
    int p;
    cin >> p >> part;
    part--;
    int len = 20 * p;
    while (p--) {
        string stmp = "";
        cin >> stmp;
        ss = ss + stmp;
        maxlen = max(maxlen, (int)stmp.size());
    }
    int s;
    cin >> s;
    F(i, 1, s) {
        string tmp;
        cin >> tmp;
        wordlst.insert(tmp);
    }
    for (auto i = wordlst.begin(); i != wordlst.end(); i++) {
        bool flag = 0;
        F(j, 1, int((*i).size()) - 1) {
            auto pos = wordlst.find((*i).substr(0, j));
            if (pos != wordlst.end() && pos != i) {
                wordlst.erase(i);
                break;
            }
            cout << *i << endl;
        }
    }
    F(i, 0, len) {
        if (i > 0) dp[0][i] = dp[0][i - 1];
        string tmp = "";
        F(j, 0, i) {
            tmp = ss[i - j] + tmp;
            dp[0][i] += wordlst.count(tmp);
        }
    }

    F(i, 1, part) {
        F(j, i + 1, len) {
            F(k, i, j - 1) {
                int t = dp[i - 1][k];
                string tmp = "";
                F(x, 0, maxlen - 1) {
                    if (j - x < k) break;
                    tmp = ss[j - x] + tmp;
                    if (wordlst.count(tmp)) t++;
                }
                dp[i][j] = max(dp[i][j], t);
            }
        }
    }

    cout << dp[part][len] << endl;

    return 0;
}
2023/12/26 16:10
加载中...