zoukankan      html  css  js  c++  java
  • HDU 5651 xiaoxin juju needs help

    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 T(T20) which represents the number of test cases.
    For each test case, there is a single line containing a string S(1length(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
    3 aa aabb a
     

    Sample Output
    1 2 1
     

    Source
     

    Recommend

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




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


    #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
    ");
                continue;
            }
            if(tag>=2)
            {
                printf("0
    ");
                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
    ",num);
    
    
        }
        return 0;
    }



  • 相关阅读:
    客户端用mstsc不能用一台设备连接终端服务器的解决办法
    [转]知识管理ABC
    Visual Studio常用小技巧[备忘]
    一套外企的数据库设计面试题
    MSDN中的图形元素和文档约定[备忘]
    设计模式概述
    ASP.Net 4.0中新增加的23项功能[转]
    Dreamweaver 8 的相关使用
    浅谈ThreadPool 线程池
    C#委托的异步调用[学习]
  • 原文地址:https://www.cnblogs.com/dacc123/p/8228753.html
Copyright © 2011-2022 走看看