DFS+剪枝。与HDOJ 1455如出一辙。
1 #include2 #include 3 #include 4 5 #define MAXN 25 6 7 int nums[MAXN], n, len, cnt; 8 char visit[MAXN]; 9 10 int comp(const void *a, const void *b) {11 return *(int *)b - *(int *)a;12 }13 14 int dfs(int cnt, int beg, int l) {15 int i, flg = 0;16 if (cnt == 3)17 return 1;18 if (l == 0) {19 for (i=0; i >2;63 qsort(nums, n, sizeof(int), comp);64 memset(visit, 0, sizeof(visit));65 j = 1;66 for (i=0; i len) {68 j = 0;69 break;70 }71 if (!j)72 printf("no\n");73 else if ( dfs(0, 0, len) )74 printf("yes\n");75 else76 printf("no\n");77 }78 }79 80 return 0;81 }