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

来源:互联网 发布:win10系统图标网络关闭 编辑:程序博客网 时间:2024/06/05 07:56
题意:给出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;}


阅读全文
0 0
原创粉丝点击