Codeforces Round #295 Div1 A(DNA Alignment)

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×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;

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;
}
时间: 2024-10-25 03:02:08

Codeforces Round #295 Div1 A(DNA Alignment)的相关文章

Codeforces Round #295 Div1 C(Pluses everywhere)

Problem 给一个有n位的数A,现要求在A中插入k个加号,使得A被分成k+1份.比如1234,插入2个加号,可变为1+234,12+34,123+4.问所有插入情况得到的数之和(mod 1e9+7),比如1+234=235,12+34=46,123+4=127–>answer=235+46+127 Limits TimeLimit(ms):3000 MemoryLimit(MB):256 n,k∈[1,105],k<n Look up Original Problem From here

Codeforces Round #295 Div1 B(Cubes)

Problem Limits TimeLimit(ms):3000 MemoryLimit(MB):256 M∈[1,105] Xi∈[?109,109] Yi∈[0,109] Look up Original Problem From here Solution 一个点可取,当且仅当,把它取了之后,上面的点不会失去平衡而掉下来. 开两个优先队列q1,q2.q1的顶元素最大,q2的顶元素最小,起初把所有可取的点都放入q1,q2,然后,轮流从q1,q2取点,如果访问过了就取下一个,取出点后,判断这

Codeforces Round #316 (Div. 2) (ABC题)

A - Elections 题意: 每一场城市选举的结果,第一关键字是票数(降序),第二关键字是序号(升序),第一位获得胜利: 最后的选举结果,第一关键字是获胜城市数(降序),第二关键字是序号(升序),第一位获得胜利: 求最后选举获胜者. 思路: 直接模拟即可. 代码: /* * @author FreeWifi_novicer * language : C++/C */ #include<cstdio> #include<iostream> #include<cstring

Codeforces Round #513解题报告(A~E)By cellur925

我是比赛地址 A:Phone Numbers $Description$:给你一串数字,问你能组成多少开头为8的11位电话号码. $Sol$:统计8的数量,与$n$%11作比较. 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 5 using namespace std; 6 7 int n,len,cnt,ans; 8 char ch[1000]; 9 10 int main() 11 {

Codeforces Round #315 (Div. 2) (ABCD题)

A. Music 题意: 一首歌长度为S秒,已经下载了T秒,下载速度为每q秒的现实时间能下载下来(q-1)秒 的歌曲.现在开始听歌,如果听到还没下载的地方就从0秒的地方开始replay,求一首歌听完需要从0秒听几次(包括一开始那次) 思路: 我们可以用路程-时间的思路来考虑这道题. 假设两位选手"播放"与"下载","播放"的起点是0m处,"下载"的起点是Tm处,终点在Sm处,"播放"的速度是1m/s,&qu

Codeforces Round #634 D. Anti-Sudoku(构造/水)

题目描述 You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here. The picture showing the correct sudoku solution: Blocks are bordered with bold black color. Your task is to change at most 9

Codeforces Round #395 (Div. 2)(未完)

2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll; const int N=1e4+5; inline int read()

【Codeforces】Codeforces Round #491 (Div. 2) (Contest 991)

题目 传送门:QWQ A:A - If at first you don't succeed... 分析: 按照题意模拟 代码: #include <bits/stdc++.h> using namespace std; int main(){ int a,b,c,n; scanf("%d%d%d%d",&a,&b,&c,&n); int ans=n-a-b+c; if(a<c || b<c) ans=-1; if(ans>

B. Nirvana Codeforces Round #549 (Div. 2) (递归dfs)

---恢复内容开始--- Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper. Help Kurt find the maximum possible product of digits among all integers from 1 to n. Input