Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
51622 AK2022071311 最优子序列 C++ 运行超时 10 1000 MS 1440 KB 1458 2022-07-13 12:19:10

Tests(2/20):


#include<iostream> #include<list> #include<vector> #include<string> #include<algorithm> #include<cstdio> using namespace std; inline int read(){ int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();} while(ch >= '0' && ch <= '9'){x = x * 10 + ch - 48; ch = getchar();} return x * f; } inline char ca(){ char ch = getchar(); while(ch < 'a' || ch > 'z') ch = getchar(); return ch; } const int N = 3005; int n, k, tp, p, maxn; struct lian{ int len; char c; }s[N]; bool b[35]; vector <string> ans; void dfs(int pos, string now, char cst){ if(pos == p + 1){ int len = now.length(); if(len == maxn) ans.push_back(now); if(len > maxn){ ans.clear(); ans.push_back(now); maxn = len; } return; } dfs(pos + 1, now, cst); // cout << pos << " " << now << endl; char cha = s[pos].c; if(!b[cha - 'a']){ b[cst - 'a'] = 1; for(int i = 1; i <= s[pos].len; i++) now = now + cha; dfs(pos + 1, now, cha); b[cst - 'a'] = 0; } return; } int main(){ n = read(), k = read(), tp = read(); for(int i = 1; i <= n; i++){ char ch = getchar(); if(p && ch == s[p].c) s[p].len++; else{ p++; s[p].len = 1; s[p].c = ch; } } dfs(1, "", 'z'); printf("%d\n", maxn); if(tp == 1) cout << ans[0] << endl; if(tp == 2){ sort(ans.begin(), ans.end()); cout << ans[0] << endl; } return 0; }


测评信息: