Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define natural unsigned short
- #define maxN 10000
- unsigned v[maxN], n;
- static char st[] = { 0, 'a', 'a', 'a','b','b','b','b', 'c', 'c', 'c' };
- natural m, p, q;
- void Init(natural k) {
- v[k] = 0;
- }
- natural Succesor(natural k) {
- if (v[k] < n) {
- v[k]++;
- return 1;
- }
- return 0;
- }
- natural Valid(natural k) {
- natural i;
- for (i = 1; i < k; i++)
- if (v[i] == v[k])
- return 0;
- return 1;
- }
- natural Solution(natural k) {
- return (k == n);
- }
- void Print() {
- natural i;
- for (i = 1; i <= n; i++)
- printf("%c", st[v[i]]);
- printf("\n");
- }
- void Back() {
- natural k = 1, isS, isV;
- Init(k);
- while (k > 0) {
- isS = 0; isV = 0;
- if (k <= n)
- do {
- isS = Succesor(k);
- if (isS) isV = Valid(k);
- } while (isS && !isV);
- if (isS)
- if (Solution(k))
- Print();
- else {
- k++;
- Init(k);
- }
- else
- k--;
- }
- }
- int main() {
- n = 10;
- Back();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement