ƵµÀÀ¸Ä¿
Ê×Ò³ > ³ÌÐò¿ª·¢ > Èí¼þ¿ª·¢ > C++ > ÕýÎÄ
C. DNA Alignment Êýѧ¹«Ê½ÍƵ¼ Codeforces Round #295 (Div. 2)
2015-03-04 09:25:10      ¸öÆÀÂÛ    À´Ô´£º  
Êղؠ  ÎÒҪͶ¸å

C. DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.

Let's assume that strings s and t have the same length n, then the function h(s,?t) is defined as the number of positions in which the respective symbols of s and t are the same. Function h(s,?t) can be used to define the function of Vasya distance ¦Ñ(s,?t):

\
where \ is obtained from string s, by applying left circular shift i times. For example,
¦Ñ("AGC",?"CGT")?=?
h("AGC",?"CGT")?+?h("AGC",?"GTC")?+?h("AGC",?"TCG")?+?
h("GCA",?"CGT")?+?h("GCA",?"GTC")?+?h("GCA",?"TCG")?+?
h("CAG",?"CGT")?+?h("CAG",?"GTC")?+?h("CAG",?"TCG")?=?
1?+?1?+?0?+?0?+?1?+?1?+?1?+?0?+?1?=?6

Vasya found a string s of length n on the Internet. Now he wants to count how many strings t there are such that the Vasya distance from the string s attains maximum possible value. Formally speaking, t must satisfy the equation: \.<†·Ÿ"/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+ClZhc3lhIGNvdWxkIG5vdCB0cnkgYWxsIHBvc3NpYmxlIHN0cmluZ3MgdG8gZmluZCBhbiBhbnN3ZXIsIHNvIGhlIG5lZWRzIHlvdXIgaGVscC4gQXMgdGhlIGFuc3dlciBtYXkgYmUgdmVyeSBsYXJnZSwgY291bnQgdGhlIG51bWJlciBvZiBzdWNoIHN0cmluZ3MgbW9kdWxvIDEwOT8mIzQzOz83LjwvcD4KCgoKSW5wdXQKPHA+ClRoZSBmaXJzdCBsaW5lIG9mIHRoZSBpbnB1dCBjb250YWlucyBhIHNpbmdsZSBpbnRlZ2VyIDxlbT5uPC9lbT4gKDE/odw/PGVtPm48L2VtPj+h3D8xMDUpLjwvcD4KPHA+ClRoZSBzZWNvbmQgbGluZSBvZiB0aGUgaW5wdXQgY29udGFpbnMgYSBzaW5nbGUgc3RyaW5nIG9mIGxlbmd0aCA8ZW0+bjwvZW0+LCBjb25zaXN0aW5nIG9mIGNoYXJhY3RlcnMg"ACGT".

Output

Print a single number ¡ª the answer modulo 109?+?7.

Sample test(s) input
1
C
output
1
input
2
AG
output
4
input
3
TTT
output
1
Note

Please note that if for two distinct strings t1 and t2 values ¦Ñ(s,?t1) §Ú ¦Ñ(s,?t2) are maximum among all possible t, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one.

In the first sample, there is ¦Ñ("C",?"C")?=?1, for the remaining strings t of length 1 the value of ¦Ñ(s,?t) is 0.

In the second sample, ¦Ñ("AG",?"AG")?=?¦Ñ("AG",?"GA")?=?¦Ñ("AG",?"AA")?=?¦Ñ("AG",?"GG")?=?4.

In the third sample, ¦Ñ("TTT",?"TTT")?=?27


ÌâÒ⣺¸øÒ»¸öÓÉA£¬T£¬C£¬G×é³ÉµÄ×Ö·û´®s£¬Çóʹ¦Ñ(s,t)×î´óµÄtµÄ¸öÊý¡£Ò×Öª£¬tÓ¦¸ÃÓÉ×Ö·û´®sÖиöÊý×î¶àµÄ×Öĸ×é³É£¨×ÜÊý×î¶àµÄ×ÖĸֻÓÐÒ»¸öµÄʱºòºÜºÃÀí½â£¬Èç¹ûÓжà¸ö×ÖĸµÄ¸öÊýÏàͬ£¬ÄÇô¾Í¿ÉÒÔ½«ÕâЩ¸öÊýÏàͬµÄ×Öĸ¿´³ÉÒ»¸ö×Öĸ£¬ÕâÑùÊǵȼ۵ģ©£¬Çó³ö×Öĸ¸öÊý×î¶àµÄÖÖÀàÊýx£¬¸ù¾ÝÅÅÁÐ×éºÏ£¬´ð°¸¾ÍÊÇx^n

´úÂ룺

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 100005
#define MAXN 2005
#define mod 1000000007
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FRE(i,a,b)  for(i = a; i <= b; i++)
#define FRL(i,a,b)  for(i = a; i < b; i++)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define DBG         pf("Hi\n")
typedef long long ll;
using namespace std;

__int64 n;
char str[maxn];
__int64 num[30];

__int64 pow_m(__int64 a,__int64 n)
{
    __int64 ret=1;
    __int64 tmp=a%mod;
    while (n)
    {
        if (n&1) ret=(ret*tmp)%mod;
        tmp=tmp*tmp%mod;
        n>>=1;
    }
    return ret;
}

int main()
{
    while (~scanf("%I64d",&n))
    {
        scanf("%s",str);
        mem(num,0);
        for (__int64 i=0;i


µã»÷¸´ÖÆÁ´½Ó ÓëºÃÓÑ·ÖÏí!»Ø±¾Õ¾Ê×Ò³
Ïà¹ØTAG±êÇ© ¹«Ê½ Êýѧ
ÉÏһƪ£º45. Jump Game II Leetcode Python
ÏÂһƪ£ºhdu 1085 Holding Bin-Laden Captive! ĸº¯ÊýµÄ»ù±¾ÔËÓ㬣¬»¹ÊDz»ÄѵÄ
Ïà¹ØÎÄÕÂ
ͼÎÄÍÆ¼ö
µã»÷ÅÅÐÐ

¹ØÓÚÎÒÃÇ | ÁªÏµÎÒÃÇ | ¹ã¸æ·þÎñ | Ͷ×ʺÏ×÷ | °æÈ¨ÉêÃ÷ | ÔÚÏß°ïÖú | ÍøÕ¾µØÍ¼ | ×÷Æ··¢²¼ | Vip¼¼ÊõÅàѵ | ¾Ù±¨ÖÐÐÄ

°æÈ¨ËùÓÐ: ºìºÚÁªÃË--ÖÂÁ¦ÓÚ×öʵÓõÄIT¼¼ÊõÑ§Ï°ÍøÕ¾