Skip to content

Instantly share code, notes, and snippets.

@theoremoon
Created February 1, 2015 09:11
Show Gist options
  • Save theoremoon/f20949720f37e6cef208 to your computer and use it in GitHub Desktop.
Save theoremoon/f20949720f37e6cef208 to your computer and use it in GitHub Desktop.
/*
* AOJ 0033
* AC
*/
#include <bits/stdc++.h>
using namespace std;
int balls[10];
int solve(int n, int a, int b) {
if (n == 10) return 1;
if (balls[n] < a && balls[n] < b) {
return -1;
}
if (balls[n] < a) {
return solve(n+1, a, balls[n]);
}
if (balls[n] < b) {
return solve(n+1, balls[n], b);
}
int x = solve(n+1, balls[n], b),
y = solve(n+1, a, balls[n]);
if (x == -1 && y == -1) return -1;
return 1;
}
int main() {
int n; cin >> n;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 10; ++j)
cin >> balls[j];
if (solve(0, 0, 0) == -1) cout << "NO" << endl;
else cout << "YES" << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment