您的位置:首页 > 其它

CS 400 Palindromic Tree 思维+构造(回文子串)

2017-11-09 20:57 369 查看
题意:给出n 求出长度为n的字符串:其不同的回文子串个数最少.n<=300

首先长度越长,回文子串的个数是非递减的.

暴力求出n<=9的情况 f(9)=8 发现n>=9 都可以构造出不同回文子串个数为8的字符串.
只要把"001011" 不断连接起来即可.  eg 001011 001011 ....

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int N=1e5+5;
string s="";
int n;
int main()
{
cin>>n;
int res=n>=9?8:n;
printf("%d\n",res);
while(s.length()<n)
s+="001011";
cout<<s.substr(0,n)<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: