Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int st[100], n, m;
- FILE *fis_out;
- void Init(int i)
- {
- st[i] = 0;
- }
- int Succesor(int k) {
- if (st[k] < n)
- {
- st[k]++;
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int Valid(k) {
- int i = 0;
- for (i = 1; i < k; i++)
- {
- if (st[i] == st[k])
- {
- return 0;
- }
- }
- return 1;
- }
- int Solution(int i)
- {
- int j;
- int ok = 0;
- if (i == m / 2)
- ok = 1;
- return ok;
- }
- void Print(FILE *fis_out) {
- int i;
- for (i = 1; i <= m / 2; i++)
- {
- fprintf(fis_out,"%d ", st[i]);
- }
- for (i = m / 2 - 1; i >= 1; i--)
- {
- fprintf(fis_out,"%d ", st[i]);
- }
- fprintf(fis_out,"\n");
- }
- void Back() {
- int vf, isS, isV;
- FILE *fis_out = fopen("out.txt", "wt");
- vf = 1;
- Init(vf);
- while (vf > 0)
- {
- isS = 0;
- isV = 0;
- if (vf <= m / 2)
- {
- do {
- isS = Succesor(vf);
- if (isS)
- {
- isV = 1;
- }
- } while (isS && !isV);
- }
- if (isS)
- {
- if (Solution(vf))
- {
- Print(fis_out);
- }
- else
- {
- vf++;
- Init(vf);
- }
- }
- else
- {
- vf--;
- }
- }
- }
- void main()
- {
- FILE *fis_in;
- fis_in = fopen("in.txt", "rt");
- fscanf(fis_in,"%d", &n);
- fscanf(fis_in,"%d", &m);
- if (m % 2 == 1)
- m++;
- Back();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement