M=1:aaaaaaaa……
M=2:DFS+manacher, 暴出N=1~25的最优解,找规律。N<=8的时候直接输出,N>8时,头两个字母一定是aa,剩下的以aababb循环,最后剩余<5全部补a,等于5补aabab。
M=3:abcabcabcabc……
#include <cstdio>
#include <cstring> using namespace std; const char str[] = "aababb"; int main()
{
int T;
int cas = ;
scanf( "%d", &T );
while ( T-- )
{
int M, N;
scanf( "%d%d", &M, &N );
printf("Case #%d: ", ++cas );
if ( M == )
{
for ( int i = ; i < N; ++i )
putchar('a');
puts("");
}
else if ( M == )
{
int cnt;
switch( N )
{
case : puts("a"); break;
case : puts("ab"); break;
case : puts("aab"); break;
case : puts("aabb"); break;
case : puts("aaaba"); break;
case : puts("aaabab"); break;
case : puts("aaababb"); break;
case : puts("aaababbb"); break;
default:
N -= ;
printf("aa");
cnt = N / ;
for ( int i = ; i < cnt; ++i )
printf( "%s", str );
N -= cnt*;
if ( N < )
{
for ( int i = ; i < N; ++i )
putchar('a');
puts("");
}
else puts("aabab"); }
}
else
{
int j = ;
for ( int i = ; i < N; ++i )
{
putchar( 'a' + j );
++j;
if ( j > ) j = ;
}
puts("");
}
}
return ;
}