关闭

Codeforces Round #295 (Div. 2) C. DNA Alignment ACM解题报告(math)

标签: acmcodeforces
360人阅读 评论(0) 收藏 举报
分类:

哎掉分ing。比赛时直接被这题吓住了,后来看了下Tutorial,顿悟了,感觉自己的思维真是还很渣呢。

What is ρ(s, t) equal to? For every character of s and every character of t there is a unique cyclic shift of t that superposes these characters (indeed, after 0, ...n - 1 shifts the character in t occupies different positions, and one of them matches the one of the character of s); therefore, there exist n cyclic shifts of s and t that superpose these characters (the situation is symmetrical for every position of the character of s). It follows that the input in ρ from a single character ti is equal to n × (the number of characters in s equal to ti). Therefore, ρ(s, t) is maximal when every character of t occurs the maximal possible number of times in s. Simply count the number of occurences for every type of characters; the answer is Kn, where K is the number of character types that occur in s most frequently. This is an O(n) solution.

题解大意就是ρ的值可以由式子求出:ρ=n*(ta*sa+tc*sc+tg*sg+tt*st),ta等为t中A的个数。

于是这么想,sa+sc+sg+st和ta+tc+tg+tt都为定值n,如何让式子值最大,假设tg tt不变,sa>sc,如果t中一个a变为c,那么ρ就变小了,所以就是sa sc sg st中大的数字,那个字母尽可能多。

如是就统计s中有多少个ACGT,如果A最多,那么t就全是A,如果A和G一样多,那么t的每一位可以为A也可以是G。

<span style="font-size:10px;">#include<bits/stdc++.h>>//新的头文件好炫酷
using namespace std;
#define MAX 20000+5
typedef long long LL;
const double pi=3.141592653589793;
const int INF=1e8;
const double inf=1e20;
const double eps=1e-6;
const int mod=1000000007;
int main(){
	int n,a[30];
	string s;
	cin>>n>>s;
	a['A'-'A']=0;
	a['C'-'A']=1;
	a['G'-'A']=2;
	a['T'-'A']=3;
	int b[4]={0,0,0,0};
	int len=s.size();
	for(int i=0;i<len;i++) b[a[s[i]-'A']]++;
	int maxn=max(max(b[0],b[1]),max(b[2],b[3]));
	int size=0;
	for(int i=0;i<4;i++) if(b[i]==maxn) size++;
	LL ans=1;
       	for(int i=0;i<len;i++) ans=(ans*size)%mod;
	printf("%I64d\n",ans);	
	return 0;
}
</span>


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:138192次
    • 积分:4420
    • 等级:
    • 排名:第7093名
    • 原创:314篇
    • 转载:5篇
    • 译文:0篇
    • 评论:46条
    最新评论