您的位置:首页 > 其它

HDU 5651组合数

2016-03-26 21:58 344 查看

xiaoxin juju needs help

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1702 Accepted Submission(s): 507



[align=left]Problem Description[/align]
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?

[align=left]Input[/align]
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).

[align=left]Output[/align]
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.

[align=left]Sample Input[/align]

3
aa
aabb
a


[align=left]Sample Output[/align]

1
2
1[code]#include<stdio.h>
#include<string.h>
#define mod 1000000007
char s[1010];
int ch[30];
int c[2010][2000];
long long int q[1010];
int main()
{
int n,y,x,T;
memset(c,0,sizeof(c));
c[0][0]=1;
for(int i=1; i<=1010; i++)
{
c[i][0]=1;
for(int j=1; j<=1010; j++)
{
c[i][j]=(c[i-1][j]+c[i-1][j-1])%1000000007;
}
}
while(~scanf("%d",&T))
{
while(T--)
{
scanf("%s",s);
int k=strlen(s);
memset(ch,0,sizeof(ch));
for(int i=0; i<k; i++)
{
ch[s[i]-'a'+1]++;
}
int sum=0,cn=0;
int f=0;
for(int i=1; i<=26; i++)
{
if(ch[i])
{
sum+=ch[i]/2;
q[cn++]=ch[i]/2;
if(ch[i]%2)
{
f++;
if(f==2)
break;
}
}

}
if(f!=2)
{
long long ans=1;
for(int i=0; i<cn; i++)
{
ans*=(c[sum][q[i]]%mod);
ans%=mod;
sum-=q[i];
}
printf("%I64d\n",ans);
}
else
printf("0\n");
}
}
return 0;
}


[/code]


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: