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;
}
首先长度越长,回文子串的个数是非递减的.
暴力求出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;
}
相关文章推荐
- CS 400 BFS-DFS 构造
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构造不含回文子串的串
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构造不含回文子串的串
- CS 400 Sorting Steps 思维(冒泡轮数)
- CS 400 Digit Permutation 思维+拓扑序
- CS 400 Root LCA Queries 思维+LCA
- CS 400 Base K Xor 思维(数位)
- CS 400 Coprime Pairs 构造!!!
- CS 400 Root LCA Queries 思维+LCA
- **[Lintcode]Longest Palindromic Substring最长回文子串
- 最长回文子串
- 最长回文子串
- 最长回文子串的长度 南邮NOJ 1968
- 判断字符串是否是回文字符串或者是否含有回文字符子串
- LeetCode(Palindrome partition 2) 求将一个字符串划分成回文子串 需要分成的段数最少是多少
- Petrozavodsk Winter-2013. Ural FU Contest Problem D. Five Palindromes manacher、一个串切割成5个回文子串、优化
- 最长回文子串
- 51nod 1089 最长回文子串 V2(Manacher算法)
- hdu 1544(求回文子串的个数)
- 求最长回文子串的Manacher算法