Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <set>
- using namespace std;
- int poeini(string s) {
- int result = 0;
- for(int i = s.size() - 1; i >= 0; i--) {
- set<char> st;
- st.insert(s[i]);
- if(i - 1 >= 0) st.insert(s[i - 1]);
- if(i - 2 >= 0) st.insert(s[i - 2]);
- result += st.size();
- }
- return result;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- int n;
- cin >> n;
- string S;
- cin >> S;
- int result = 0;
- if(n <= 22) {
- for(int mask = 0; mask < (1 << n); mask++) {
- string prva = "", vtora = "";
- for(int i = 0; i < n; i++) {
- if(mask & (1 << i)) {
- prva += S[i];
- }
- else {
- vtora += S[i];
- }
- }
- result = max(result, poeini(prva) + poeini(vtora));
- }
- }
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement