HDU多校训练-Distinct Sub-palindromes

Problem Description:
S is a string of length n. S consists of lowercase English alphabets.
Your task is to count the number of different S with the minimum number of distinct sub-palindromes. Sub-palindrome is a palindromic substring.
Two sub-palindromes u and v are distinct if their lengths are different or for some i (0≤i≤length), u i u_i ui v i v_i vi. For example, string “aaaa” contains only 4 distinct sub-palindromes which are “a”, “aa”, “aaa” and “aaaa”.ui≠vi. For example, string “aaaa” contains only 4 distinct sub-palindromes which are “a”, “aa”, “aaa” and “aaaa”.
Key:找出数量最少的子回文串(长度可以不同),求他们构成不同字符串S的数量。
推导:
n=1时,子回文种类数最少为1,S的数量为26。
n=2时,S的类型有aa,ab(ba)两种,第一种子串有a,aa;第二种子串有a,b,即最少子回文种类数为2。S的数量为2626=676。
n=3时,S的类型有aaa,aab,aba,baa,abc等,aaa子回文有a,aa,aaa;aab子回文有a,aa,b;aba子回文有a,b,aba;baa子回文有b,a,aa;abc子回文有a,b,c,经推导最少子回文种类数为3.S的数量为26
26*26=17576.
n=4时,S的类型有aaaa,aaab,aabb,abca,abcd等,aaaa,aaab,aabb,abcd等子回文种类数为4,abca子回文a,b,c为3,即最少子回文种类数为3,S的数量就是从26字母选三个A(26,3)=15600。
以此类推,可得n=5,6,…时,最少子回文种类数均为3,且S类型为abcabcabc…;所以S的数量均为15600
代码如下

#include<iostream>
int main(){
	int t;
	scanf("%d",&t);
	int n[t];
	for(int i = 0;i < t;i++){
		scanf("%d",&n[i]);
	}
	for(int i = 0;i < t;i++){
		if(n[i]==1){printf("26\n");}
		else if(n[i]==2){printf("676\n");}
		else if(n[i]==3){printf("17576\n");}
		else{printf("15600\n");}
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值