题目
题意:构造两个字符串
,
,使
在
中作为子序列的出现次数恰好等于
。
其中
;
,
的长度不能超过
。
在构造过程中保证使
为新字符
: 令
(
中含有
)
: 令
#include<bits/stdc++.h>
using namespace std;
string p,s;
int n;
void dfs(int n,char c){
if (n==1){
s+=c,p+=c;
return;
}else if (n==2){
s+=c,s+=c,p+=c;
return;
}
if (n&1){
dfs(n/2,c+1);
s=p+c+s.substr(p.size(),s.size()-p.size()+1)+c+c,p+=c;
}else{
dfs(n/2-1,c+1);
s=p+c+c+s.substr(p.size(),s.size()-p.size()+1)+c+c,p+=c;
}
}
int main(){
scanf("%d",&n);
dfs(n,'a');
cout<<s<<' '<<p;
}