Advertisement
Patey

Untitled

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