Advertisement
Alx09

Untitled

Jun 1st, 2020
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define natural unsigned short
  5. #define maxN 10000
  6. unsigned v[maxN], n, j;
  7. static short st[] = { 0 , 3 , 5, 7 };
  8.  
  9. void Init(natural k) {
  10.     v[k] = 0;
  11. }
  12. natural Succesor(natural k) {
  13.     if (v[k] < 3) {
  14.         v[k]++;
  15.         return 1;
  16.     }
  17.     return 0;
  18. }
  19.  
  20. natural Valid(natural k) {
  21.     return 1;
  22. }
  23.  
  24. natural Solution(natural k) {
  25.     return (k == n);
  26. }
  27.  
  28. void Print() {
  29.     natural i;
  30.  
  31.     for (i = 1; i <= n; i++)
  32.         printf("%d ", st[v[i]]);
  33.     printf("\n");
  34. }
  35.  
  36. void Back() {
  37.     natural k = 1, isS, isV;
  38.     Init(k);
  39.     while (k > 0) {
  40.         isS = 0; isV = 0;
  41.         if (k <= n)
  42.             do {
  43.                 isS = Succesor(k);
  44.                 if (isS) isV = Valid(k);
  45.             } while (isS && !isV);
  46.             if (isS)
  47.                 if (Solution(k))
  48.                     Print();
  49.                 else {
  50.                     k++;
  51.                     Init(k);
  52.                 }
  53.             else
  54.                 k--;
  55.     }
  56. }
  57.  
  58. int main() {
  59.     do {
  60.         system("cls");
  61.         printf("n = "); scanf("%d", &n);
  62.     } while (n >= maxN && j);
  63.     Back();
  64.     system("pause");
  65.     return 0;
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement