Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream cin("scode.in");
- ofstream cout("scode.out");
- int combos(string s)
- {
- int a = 1, n = s.size();
- if((n & 1) == 0 || n == 1) // A -> A
- return 1;
- if(s.substr(0, n/2) == s.substr(n/2, n/2)) // ABC -> AB + ABC
- a += combos(s.substr(n/2, n/2+1));
- if(s.substr(0, n/2) == s.substr(n/2+1, n/2)) // ABC -> ABC + AB
- a += combos(s.substr(0, n/2+1));
- if(s.substr(0, n/2) == s.substr(n/2+1, n/2)) // ABC -> BC + ABC
- a += combos(s.substr(n/2, n/2+1));
- if(s.substr(1, n/2) == s.substr(n/2+1, n/2)) // ABC -> ABC + BC
- a += combos(s.substr(0, n/2+1));
- return a;
- }
- int main()
- {
- string s;
- cin >> s;
- cout << combos(s) - 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement