xiaoxin juju needs help
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 594 Accepted Submission(s): 175
Problem Description
As we all known, xiaoxin is a brilliant coder. He knew **palindromic** strings when he was only a six grade student at elementry school.
This summer he was working at Tencent as an intern. One day his leader came to ask xiaoxin for help. His leader gave him a string and he wanted xiaoxin to generate palindromic strings for him. Once xiaoxin generates a different palindromic string, his leader will give him a watermelon candy. The problem is how many candies xiaoxin's leader needs to buy?
Input
This problem has multi test cases. First line contains a single integer
T(T≤20) which represents the number of test cases.
For each test case, there is a single line containing a string
S(1≤length(S)≤1,000).
Output
For each test case, print an integer which is the number of watermelon candies xiaoxin's leader needs to buy after mod
1,000,000,007.
Sample Input
Sample Output
Source
BestCoder Round #77 (div.2)
无语了,求杨辉三角居然忘了注意边界C(n, 0) = 1,求的时候取模还不彻底,无语......失之毫厘谬以千里......
思路主要就是判断字符串长度的奇偶性,结合每个元素的奇偶性来判断有没有可能组成回文
如果可以的话然后利用组合数来算有多少种
比如
cccbba a abbccc
len = 13 但是实际上只要算len / 2 = 6也就是黑体的这一半的组合情况就行了,另外一半对称
算法是,如果取a,b,c的顺序,那么对于a:C(6, 1),对于b去掉a占的位置:C(6 - 1, 2) = C(5, 2)
对于c去掉b, a占得位置:C(6 - 1 - 2, 3) = C(3, 3)
根据乘法原理ans = C(6, 1) * C(5, 2) * C(3, 3)
偶数情况以此类推
#include
#include
#include
#include
#include
#include
#include