现在的位置: 首页 > 综合 > 正文

Zoj 1076 Gene Assembly

2018年01月15日 ⁄ 综合 ⁄ 共 2466字 ⁄ 字号 评论关闭

Gene Assembly


Time Limit: 2 Seconds     
Memory Limit:
65536 KB


Statement of the Problem

With the large amount of genomic DNA sequence data being made available, it is becoming more important to find genes (parts of the genomic DNA which are responsible for the synthesis of proteins) in these sequences. It is known that for eukaryotes (in contrast
to prokaryotes) the process is more complicated, because of the presence of junk DNA that interrupts the coding region of genes in the genomic sequence. That is, a gene is composed by several pieces (called exons) of coding regions. It is known that the order
of the exons is maintained in the protein synthesis process, but the number of exons and their lengths can be arbitrary.

Most gene finding algorithms have two steps: in the first they search for possible exons; in the second they try to assemble a largest possible gene, by finding a chain with the largest possible number of exons. This chain must obey the order in which the
exons appear in the genomic sequence. We say that exon i appears before exon j if the end of i precedes the beginning of j.

The objective of this problem is, given a set of possible exons, to find the chain with the largest possible number of exons that cound be assembled to generate a gene.

Input Format

Several input instances are given. Each instance begins with the number 0 < n < 1000 of possible exons in the sequence. Then, each of the next n lines contains a pair of integer numbers that represent the position in which the exon starts and ends in the
genomic sequence. You can suppose that the genomic sequence has at most 50000 basis. The input ends with a line with a single 0.

Output Format

For each input instance your program should print in one line the chain with the largest possible number of exons, by enumerating the exons in the chain. If there is more than one chain with the same number of exons, your program can print anyone of them.

Sample Input

6
340 500
220 470
100 300
880 943
525 556
612 776
3
705 773
124 337
453 665
0

Sample Output

3 1 5 6 4
2 3 1

暴力?。

#include<cstdio>
#include<algorithm>

using namespace std;

struct Node{
    int a,b;
    int flag,p,ff;
}num[1100];

bool cmp1(Node x,Node y)
{
    if(x.a!=y.a)
        return x.a<y.a;
    return x.b<y.b;
}

int cnt[1100];

int main()
{
    int n;
    int i,j;
    int count,s;

    while(scanf("%d",&n),n)
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&num[i].a,&num[i].b);
            num[i].flag=0; num[i].p=-1;
            num[i].ff=i;
        }
        sort(num+1,num+1+n,cmp1);

        for(i=1;i<=n;i++)
        {
            int tmp=0;
            for(j=1;j<i;j++)
            {
                if(num[i].a>num[j].b)
                    tmp=num[j].flag;
            }
            num[i].flag=tmp+1;
            for(j=1;j<i;j++)
            {
                if(num[i].flag==num[j].flag+1 && num[i].a>num[j].b)
                    num[i].p=j;
            }
        }
        count=0;
        for(i=1;i<=n;i++)
        {
            if(num[i].flag>count)
                count=num[i].flag;
        }
        for(i=n;i>=1;i--)
        {
            if(num[i].flag==count)
                break;
        }
        s=count;
        cnt[count--]=num[i].ff;
        while(count)
        {
            i=num[i].p;
            cnt[count--]=num[i].ff;
        }
        for(i=1;i<=s;i++)
            printf("%d%c",cnt[i],i==s?'\n':' ');
    }
    return 0;
}

抱歉!评论已关闭.