Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int st[100], vf,n;
- void Init(int i)
- {
- st[i] = 0;
- }
- int Succesor(int k)
- {
- if (st[k] < n)
- {
- st[k]++;
- return 1;
- }
- return 0;
- }
- int Solution(int k)
- {
- int i,j,l;
- if (k < n)
- return 0;
- for (i = 1; i < k; i++)
- {
- for (j = i + 1; j <= k; j++)
- {
- if (st[i] == st[j])
- return 0;
- }
- }
- for (i = 1; i < k-1;i++)
- {
- for (l = i + 1; l < k; l++)
- {
- for (j = l + 1; j <= k; j++)
- {
- if (st[l] == ((st[i] + st[j])/2))
- return 0;
- }
- }
- }
- return 1;
- }
- void Print()
- {
- int i;
- for (i = 1; i <= n; i++)
- {
- printf("%d ", st[i]);
- }
- printf("\n");
- }
- void Back()
- {
- int isS, isV=1;
- vf = 1;
- Init(vf);
- while (vf > 0)
- {
- isS = 0;
- if (vf <= n)
- {
- do {
- isS = Succesor(vf);
- } while (isS && !isV);
- }
- if (isS)
- {
- if (Solution(vf))
- {
- Print();
- }
- else
- {
- vf++;
- Init(vf);
- }
- }
- else
- {
- vf--;
- }
- }
- }
- void main()
- {
- printf("Dati n= \n");
- scanf("%d", &n);
- printf("\n");
- Back();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement