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

原创 2015年03月03日 13:32:02

哎掉分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>


版权声明:本文为博主原创文章,未经博主允许不得转载。

C. DNA Alignment(Codeforces Round #295(div2))

C. DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input ...
  • caduca
  • caduca
  • 2015年03月02日 18:27
  • 2854

C. DNA Alignment 数学公式推导 Codeforces Round #295 (Div. 2)

题意:给一个由A,T,C,G组成的字符串s,求使ρ(s,t)最大的t的个数。易知,t应该由字符串s中个数最多的字母组成(总数最多的字母只有一个的时候很好理解,如果有多个字母的个数相同,那么就可以将这些...

**Codeforces Round #250 (Div. 2) C. The Child and Toy ACM解题报告(贪心难题)

今天是惨遭吊打,和学长做去年的儿童节专场,只做出来A题,B题直接暴力以为会超时,dp了半天过不了,C题贪心贪错了。。。 这题的大意是有n个部件,要把他们全部破坏,破坏i就需要与i相连的那些部件的能量...

**Codeforces Round #282 (Div. 2) C. Treasure ACM解题报告(构造难题)

Malek has recently found a treasure map. While he was looking for a treasure he found a locked door....

Codeforces Round #295 C. DNA Alignment

C. DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes ...

codeforces Round #264(div2) C解题报告

C. Gargari and Bishops time limit per test 3 seconds memory limit per test 256 megabytes...

Codeforces Round #297 (Div. 2) C. Ilya and Sticks 解题报告

CodeforcesRound #297 (Div. 2)   C. Ilya and Sticks 结题报告   题目分类:贪心策略   题目描述:给n (1 ≤ n ≤ 105) 根...

codeforces Round #272(div2) C解题报告

C. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes...

Codeforces Round #283(Div.2) A,B,C,D,E 解题报告

Codeforces Round #283(Div.2) A,B,C,D,E 解题报告 codeforces 上写的题解 by Endagorion: http://codeforces.com/...

codeforces Round #261(div2) C解题报告

把这题抽象一下,每个人,在1~K个数中选数字,组成d长度的序列,要求每个序列不能完全相同,数字可以重复选。 进一步抽象一下,每个人的乘坐公交的序列,就是d位k进制数,最多可以分配的序列个数为 k^d。...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces Round #295 (Div. 2) C. DNA Alignment ACM解题报告(math)
举报原因:
原因补充:

(最多只允许输入30个字)