Created
October 6, 2013 01:44
-
-
Save msg555/6848329 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
string S; | |
int result; | |
void solve(int x, int L, int N, int ones) { | |
if (result > 1) return; | |
if (L < N || N < 0) return; | |
if (x == S.size()) { | |
result += L == 0; | |
return; | |
} | |
if (S[x] == '1') { | |
if (ones <= 1) { | |
solve(x + 1, L - 1, N - 1, ones + 1); | |
} | |
int sz = 0; | |
for(int i = x; ones == 0 && i < S.size() && sz <= N; i++) { | |
sz = 2 * sz + (S[i] == '1' ? 1 : 0); | |
if (sz >= 3) { | |
solve(i + 1, L - sz, N - sz, sz); | |
} | |
} | |
} | |
if (S[x] == '0') { | |
solve(x + 1, L - 1, N, 0); | |
} | |
} | |
int main() { | |
for(int L, N, t = 1; (cin >> L >> N) && L; t++) { | |
cin >> S; | |
result = 0; | |
solve(0, L, N, 0); | |
cout << "Case #" << t << ": "; | |
if (result == 0) { | |
cout << "NO\n"; | |
} else if (result == 1) { | |
cout << "YES\n"; | |
} else { | |
cout << "NOT UNIQUE\n"; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment