Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- unsigned long pairs_count;
- unsigned long *brackets;
- unsigned long found = 0;
- void print_result()
- {
- unsigned long i, j;
- for (i = 0; i < pairs_count; i++) {
- printf("(");
- for (j = 0; j < pairs_count; j++)
- if (brackets[j] == i)
- printf(")");
- }
- printf("n");
- found++;
- }
- void step(unsigned long start_val, unsigned long pos)
- {
- unsigned long k, i;
- if (start_val > pos)
- k = start_val;
- else
- k = pos;
- for (i = k; i < pairs_count; i++) {
- brackets[pos] = i;
- if (pos == pairs_count - 1)
- print_result();
- else
- step(i, pos + 1);
- }
- }
- int main()
- {
- scanf("%d", &pairs_count);
- brackets = new unsigned long[pairs_count];
- if (!brackets) {
- printf("Unsufficient memory.n");
- return (0);
- }
- step(0, 0);
- delete brackets;
- printf("Found: %d.n", found);
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement