CodeForces - 520C DNA Alignment 推规律

题意:

恶心,给定 字符串 S,找到一个串T 使得  那个值最大

思路:

要使得 这个值最大,我们可以推出来(自己算算),另一个串的所有数字跟 S 串中,出现次数最到的字符一样就是了,,

如果S中出现次数最多的字符不止一种,那 另一个串中所有的字符只要是这些出现次数最多的就行了

所以串T中 每个位置的选择种数 就是S串中出现次数最多的字符 的种类数,,最后求个快速幂


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<map>
#define PI acos(-1.0)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e5 + 7, maxd = 20 + 7, mod = 1e9 + 7;
const int INF = 0x7f7f7f7f;

int n;
string s, t = "ATGC";
map<char, ll> mp;
ll max_ = -1, cnt, ans = 1;

int main() {

    ios::sync_with_stdio(0);
    cin >> n >> s;
    for(int i = 0; i < n; ++i)
        mp[s[i]]++;
    for(int i = 0; i < 4; ++i) {
        if(mp[t[i]] == max_) {
            cnt++;
        }
        else if(mp[t[i]] > max_) {
            max_ = mp[t[i]];
            cnt = 1;
        }
    }
    while(n) {
        if(n & 1) ans *= cnt;
        ans %= mod;
        n >>= 1;
        cnt = (cnt*cnt % mod);
    }
    cout << ans << endl;

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值