TimeLimit(ms):2000
MemoryLimit(MB):256
n∈[1,105]
字符集∈[A,G,C,T]
设
Ni 表示s 串中A,G,C,T 出现的次数,Mi 表示t 串中A,G,C,T 出现的次数,则max=∑4i=1Ni×Mi ,Ni 越大,对max 的贡献越大,应当分配的Mi 越多。
answer=an ,由推公式得知。当
a=1 时,answer=1 ;当
a=2 时,answer=C0n+C1n+…+Cnn=2n ;当
a=2 时,answer=C0n2n+C1n2n?1+…+Cnn20=(1+2)n=3n ;当
a=3 时,answer=C0n3n+C1n3n?1+…+Cnn30=(1+3)n=4n ;
TimeComplexity:O(n)
MemoryComplexity:O(n)
//Hello. I‘m Peter.
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<cctype>
#include<ctime>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double ld;
#define peter cout<<"i am peter"<<endl
#define input freopen("data.txt","r",stdin)
#define randin srand((unsigned int)time(NULL))
#define INT (0x3f3f3f3f)*2
#define LL (0x3f3f3f3f3f3f3f3f)*2
#define gsize(a) (int)a.size()
#define len(a) (int)strlen(a)
#define slen(s) (int)s.length()
#define pb(a) push_back(a)
#define clr(a) memset(a,0,sizeof(a))
#define clr_minus1(a) memset(a,-1,sizeof(a))
#define clr_INT(a) memset(a,INT,sizeof(a))
#define clr_true(a) memset(a,true,sizeof(a))
#define clr_false(a) memset(a,false,sizeof(a))
#define clr_queue(q) while(!q.empty()) q.pop()
#define clr_stack(s) while(!s.empty()) s.pop()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define dep(i, a, b) for (int i = a; i > b; i--)
#define repin(i, a, b) for (int i = a; i <= b; i++)
#define depin(i, a, b) for (int i = a; i >= b; i--)
#define pi 3.1415926535898
#define eps 1e-6
#define MOD 1000000007
#define MAXN 200100
#define N 100100
#define M 20
int n,lens;
char s[N];
int num[4];
int idx(char c){
if(c==‘A‘) return 0;
else if(c==‘C‘) return 1;
else if(c==‘G‘) return 2;
else return 3;
}
const ll p=1e9+7;
ll quick_power(ll x,ll y){
if(y==0) return 1;
ll res=quick_power(x,y>>1);
if(y%2==0) return res*res%p;
else return (res*res%p)*x%p;
}
int main(){
scanf("%d",&lens);
scanf("%s",s);
rep(i,0,lens){
int c=idx(s[i]);
num[c]+=1;
}
int maxi=0;
rep(i,0,4){
maxi=max(maxi,num[i]);
}
int n=0;
rep(i,0,4){
if(num[i]==maxi) n+=1;
}
cout<<quick_power(n,lens)<<endl;
}
Codeforces Round #295 Div1 A(DNA Alignment)
原文地址:http://blog.csdn.net/uestc_peterpan/article/details/44022431