Bovine Genomics

题目描述

Farmer John owns N cows with spots and N cows without spots. Having just completed a course in bovine genetics, he is convinced that the spots on his cows are caused by mutations in the bovine genome.
At great expense, Farmer John sequences the genomes of his cows. Each genome is a string of length M built from the four characters A, C, G, and T. When he lines up the genomes of his cows, he gets a table like the following, shown here for N=3:

Positions: 1 2 3 4 5 6 7 … M

Spotty Cow 1: A A T C C C A … T
Spotty Cow 2: G A T T G C A … A
Spotty Cow 3: G G T C G C A … A

Plain Cow 1: A C T C C C A … G
Plain Cow 2: A G T T G C A … T
Plain Cow 3: A G T T C C A … T
Looking carefully at this table, he surmises that positions 2 and 4 are sufficient to explain spottiness. That is, by looking at the characters in just these two positions, Farmer John can predict which of his cows are spotty and which are not (for example, if he sees G and C, the cow must be spotty).

Farmer John is convinced that spottiness can be explained not by just one or two positions in the genome, but by looking at a set of three distinct positions. Please help him count the number of sets of three distinct positions that can each explain spottiness.

输入

The first line of input contains N (1≤N≤500) and M (3≤M≤50). The next N lines each contain a string of M characters; these describe the genomes of the spotty cows. The final N lines describe the genomes of the plain cows.

输出

Please count the number of sets of three distinct positions that can explain spottiness. A set of three positions explains spottiness if the spottiness trait can be predicted with perfect accuracy among Farmer John’s population of cows by looking at just those three locations in the genome.

样例输入

3 8
AATCCCAT
GATTGCAA
GGTCGCAA
ACTCCCAG
ACTCGCAT
ACTTCCAT

样例输出

22


题意

前三行就是有斑点的牛的基因型的字符串,后三行是没有斑点的牛的基因型的字符串,每三个碱基判断一下前三行出现过的后三行是否出现过。直接暴力,但是判断是否出现过是要用一个比较巧妙地办法,避免直接判断,直接判断会超时。
用数组下标来判断。详细见代码。


代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#define  mem(a)  memset(a,0,sizeof(a))
using namespace std;

int a[1005][1005];


int main ()
{

#ifndef ONLINE_JUDGE
    freopen("1","r",stdin);
#endif // ONLINE_JUDGE
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //mem(a);
    map <char,int> M;
    int m,n;
    char c;
    M['A']=1;
    M['T']=2;
    M['G']=3;
    M['C']=4;
    cin>>m>>n;
    for(int i=0; i<m*2; ++i)
    {
        for(int j=0; j<n; ++j)
        {
            cin>>c;
            a[i][j]=M[c];
        }
    }
    int ans=0;
    for(int i=0; i<n; ++i)
        for(int j=i+1; j<n; ++j)
            for(int k=j+1; k<n; ++k)
            {
                bool p[1000];
                mem(p);
                bool flag=true;
                for(int c=0; c<m; ++c)
                    p[a[c][i] + a[c][j]*6 + a[c][k]*25] = true;
                for(int d=m; d<2*m; ++d)
                    if(p[a[d][i] + a[d][j]*6 + a[d][k]*25] == true)
                        flag=false;
                if(flag)
                    ans++;
            }
    cout<<ans<<endl;
    return 0;
}

/**************************************************************
    Language: C++
    Result: 正确
    Time:208 ms
    Memory:5648 kb
****************************************************************/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

渴鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值