UVA 129(p195)----Krypton Factor

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100;
int a[maxn];
int n,l,cnt;
int solve(int dep)
{
    if(cnt++==n)
    {
        for(int i=0; i<dep; i++)
        {
            if(i%64==0&&i) printf("\n");
            else if(i%4==0&&i) printf(" ");
            printf("%c",'A'+a[i]);
        }
        printf("\n%d\n",dep);
        return 0;
    }
    for(int i=0; i<l; i++)
    {
        a[dep]=i;
        int flag=1;
        for(int j=1; 2*j<=dep+1; j++)
        {
            int Equal=1;
            for(int k=0; k<j; k++)
                if(a[dep-k]!=a[dep-j-k])
                {
                    Equal=0;
                    break;
                }
            if(Equal)
            {
                flag=0;
                break;
            }
        }
        if(flag)
            if(!solve(dep+1))
                return 0;
    }
    return 1;
}
int main()
{
    while(scanf("%d%d",&n,&l)==2&&n)
    {
        cnt=0;
        solve(0);
    }
    return 0;
}
题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=65

你可能感兴趣的:(UVA 129(p195)----Krypton Factor)