URAL 2037 Richness of binary words (回文子串,找规律)
Richness of binary words
题目链接:
http://acm.hust.edu.cn/vjudge/contest/126823#problem/B
Description
For each integer i from 1 to n, you must print a string s i of length n consisting of letters ‘a’ and ‘b’ only. The string s i must contain exactly i distinct palindrome substrings. Two substrings are considered distinct if they are different as strings.Input
The input contains one integer n (1 ≤ n ≤ 2000).Output
You must print n lines. If for some i, the answer exists, print it in the form “ i : s i” where s i is one of possible strings. Otherwise, print “ i : NO”.Sample Input
input output
4
1 : NO
2 : NO
3 : NO
4 : aaaa
##题意: 要求输出n个长度为n的字符串(只能放a或b): 要求Si中不同回文子串的个数恰为i.
##题解: 本质就是找出一种构造方式使得回文子串个数不会再增加. 参考2015-ICPC合肥现场赛H题: http://blog.csdn.net/snowy_smile/article/details/49870109 http://blog.csdn.net/keshuai19940722/article/details/49839359
##代码: ``` cpp #include