标签:
1 #include <cstdio> 2 3 int isValid(int a[], int low, int high) { 4 if (low >= high) 5 return 1; 6 7 int root = a[high]; 8 int i = low; 9 while (a[i] < root && i <= high) 10 i++; 11 for (int j = i; j < high; j++) 12 if (a[j] < root) 13 return false; 14 return isValid(a, low, i - 1) && isValid(a, i, high - 1); 15 } 16 17 int main() { 18 int n; 19 while (scanf("%d", &n) != EOF) { 20 int a[n]; 21 for (int i = 0; i < n; ++i) 22 scanf("%d", &a[i]); 23 24 if (isValid(a, 0, n - 1)) { 25 printf("Yes\n"); 26 } else { 27 printf("No\n"); 28 } 29 } 30 return 0; 31 } 32 /************************************************************** 33 Problem: 1367 34 User: tonyhu 35 Language: C++ 36 Result: Accepted 37 Time:10 ms 38 Memory:1020 kb 39 ****************************************************************/
标签:
原文地址:http://www.cnblogs.com/tonyhu1993/p/4702979.html