您的位置:首页 > 其它

UVA 129(p195)----Krypton Factor

2016-02-25 22:29 351 查看
#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: