Skip to content

Instantly share code, notes, and snippets.

@aajjbb
Created October 27, 2013 03:08
Show Gist options
  • Save aajjbb/7177553 to your computer and use it in GitHub Desktop.
Save aajjbb/7177553 to your computer and use it in GitHub Desktop.
class LittleElephantAndIntervalsDiv2 {
public:
int getNumber(int, vector <int>, vector <int>);
};
int LittleElephantAndIntervalsDiv2::getNumber(int M, vector <int> L, vector <int> R) {
//0 - W, 1 - B
vector<int> base(M, 0);
queue<pair<vector<int>, int> > q;
set<vector<int> > ans;
q.push(make_pair(base, 0));
int i;
for ( ; !q.empty(); ) {
vector<int> now = q.front().first;
int id = q.front().second;
q.pop();
if (id == L.size()) {
ans.insert(now);
continue;
}
vector<int> na = now;
vector<int> nb = now;
for (i = L[id] - 1; i <= R[id] - 1; i++) {
na[i] = 0;
nb[i] = 1;
}
q.push(make_pair(na, id + 1));
q.push(make_pair(nb, id + 1));
}
return ans.size();
}
//Powered by [KawigiEdit] 2.0!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment