前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDU 5651 xiaoxin juju needs help

HDU 5651 xiaoxin juju needs help

作者头像
ShenduCC
发布2018-04-26 14:44:02
5390
发布2018-04-26 14:44:02
举报
文章被收录于专栏:算法修养

xiaoxin juju needs help

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

Total Submission(s): 665    Accepted Submission(s): 196

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  which represents the number of test cases. For each test case, there is a single line containing a string .

Output

For each test case, print an integer which is the number of watermelon candies xiaoxin's leader needs to buy after mod .

Sample Input

代码语言:javascript
复制
3
aa
aabb
a

Sample Output

代码语言:javascript
复制
1
2
1

Source

BestCoder Round #77 (div.2)

Recommend

wange2014   |   We have carefully selected several similar problems for you:  5654 5653 5650 5649 5648

可以统计每个字符出现的个数,然后分别除以2,也就是对回文串的一半进行排列组合

代码语言:javascript
复制
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <map>

using namespace std;
const __int64 mod=1e9+7;
char a[1005];
int t;
int res[1005];
map<char,int> m;
int a1[1000][1000];
void init()
{
    a1[1][1]=1;
    for(int i=2;i<=600;i++)
    {
        for(int j=1;j<=i;j++)
        {
            if(j==1)
                a1[i][j]=1;
            else if(j==i)
                a1[i][j]=1;
            else
                a1[i][j]=(a1[i-1][j]+a1[i-1][j-1])%mod;
        }
    }
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",a);
        int len=strlen(a);
        m.clear();
        int tag=0;
        //cout<<m[a[1]]<<endl;

        for(int i=0;i<len;i++)
        {
            m[a[i]]++;
        }
        int cnt=1;
        init();
        memset(res,0,sizeof(res));
        __int64 sum=0;
        for(int i=0;i<len;i++)
        {
            if(m[a[i]]==-1)
                continue;
             if(m[a[i]]&1)
                tag++;
            res[cnt++]=(m[a[i]])/2;
            sum+=(m[a[i]])/2;
            m[a[i]]=-1;
        }
        if(tag==1&&(!(len&1)))
        {
            printf("0\n");
            continue;
        }
        if(tag>=2)
        {
            printf("0\n");
            continue;
        }
        __int64 num=1;
        
        for(int i=1;i<cnt;i++)
        {
            num=(num*a1[sum+1][res[i]+1])%mod;
            sum-=res[i];
        }
        printf("%I64d\n",num);


    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-03-27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • xiaoxin juju needs help
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档