码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #295 Div1 A(DNA Alignment)

时间:2015-03-02 21:02:32      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:数学   组合数   

Problem

技术分享

Limits

TimeLimit(ms):2000

MemoryLimit(MB):256

n[1,105]

[A,G,C,T]

Look up Original Problem From here

Solution

Ni表示s串中A,G,C,T出现的次数,Mi表示t串中A,G,C,T出现的次数,则max=4i=1Ni×MiNi越大,对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

Complexity

TimeComplexity:O(n)

MemoryComplexity:O(n)

My Code

//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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!