Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- bool isValid(string s){
- if(s[0]=='M' && s[1]=='M') return false;
- if(s[s.length()-1]=='M' && s[s.length()-2]=='M') return false;
- for(int i=1; i<s.length()-1; i++){
- if(s[i]=='W') continue;
- if(s[i-1]=='W' || s[i+1]=='W') continue;
- else return false;
- }
- return true;
- }
- int main() {
- string s = "MMMMMWWWWWWW";
- int m=0, n=1;
- if(isValid(s)) {m++;}
- while(next_permutation(s.begin(), s.end())){
- // cout<<s<<endl;
- n++;
- if(isValid(s)){
- m++;
- }
- }
- cout<<m<<" "<<n<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement