Advertisement
Patey

Untitled

Apr 15th, 2021
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int st[100],n,m;
  5.  
  6. void Init(int i)
  7. {
  8.     st[i] = 0;
  9. }
  10.  
  11. int Succesor(int k) {
  12.     if (st[k] < n)
  13.     {
  14.         st[k]++;
  15.         return 1;
  16.     }
  17.     else
  18.     {
  19.         return 0;
  20.     }
  21. }
  22.  
  23. int Valid(k) {
  24.     int i = 0;
  25.     for (i = 1; i < k; i++)
  26.     {
  27.         if (st[i] == st[k])
  28.         {
  29.             return 0;
  30.         }
  31.     }
  32.     return 1;
  33. }
  34.  
  35.  
  36. int Solution(int i)
  37. {
  38.     int j;
  39.     int ok = 0;
  40.     if (i == m/2)
  41.         ok = 1;
  42.     return ok;
  43. }
  44.  
  45. void Print() {
  46.     int i;
  47.     for (i = 1; i <= m/2; i++)
  48.     {
  49.         printf("%d ", st[i]);
  50.     }
  51.     for (i = m / 2 - 1; i >= 1; i--)
  52.     {
  53.         printf("%d ", st[i]);
  54.     }
  55.     printf("\n");
  56. }
  57.  
  58. void Back() {
  59.     int vf, isS, isV;
  60.     vf = 1;
  61.     Init(vf);
  62.     while (vf > 0)
  63.     {
  64.         isS = 0;
  65.         isV = 0;
  66.         if (vf <= m/2)
  67.         {
  68.             do {
  69.                 isS = Succesor(vf);
  70.                 if (isS)
  71.                 {
  72.                     isV = 1;
  73.                 }
  74.             } while (isS && !isV);
  75.         }
  76.         if (isS)
  77.         {
  78.             if (Solution(vf))
  79.             {
  80.                 Print();
  81.             }
  82.             else
  83.             {  
  84.                 vf++;
  85.                 Init(vf);
  86.             }
  87.         }
  88.         else
  89.         {
  90.             vf--;
  91.         }
  92.     }
  93. }
  94.  
  95. void main()
  96. {
  97.     printf("n= ");
  98.     scanf("%d", &n);
  99.     printf("m= ");
  100.     scanf("%d", &m);
  101.     if (m % 2 == 1)
  102.         m++;
  103.     Back();
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement