ZOJ 1076 Gene Assembly (贪心水题)

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

扫描二维码关注公众号,回复: 1737777 查看本文章

Source: South America 2001


#include<iostream>
#include<algorithm>
#include<string>
#include<map>//int dx[4]={0,0,-1,1};int dy[4]={-1,1,0,0};
#include<set>//int gcd(int a,int b){return b?gcd(b,a%b):a;}
#include<vector>
#include<cmath>
#include<stack>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define mod 1e9+7
#define ll long long
#define maxn 1005
using namespace std;
int n;
struct node
{
    int b,e,num;
    node(){};
};
node seq[maxn];
bool cmp(node x,node y)
{
    return x.e<y.e;
}
/*
给定n个二元组,分别表示开始和结束,
只有结束在开始之前才可以拼接,
所以是一个很典型的活动选择问题,,
只要按结束时间从小到大排序。
*/
int main()
{
    ios::sync_with_stdio(false);
    while(cin>>n&&n)
    {
        for(int i=0;i<n;i++)
        {
            cin>>seq[i].b>>seq[i].e;
            seq[i].num=i+1;
        }
        sort(seq,seq+n,cmp);
        int tp=seq[0].e;
        cout<<seq[0].num;
        int i=1;
        while(1)
        {
            while(seq[i].b<=tp) i++;
            if(i>=n) break;
            tp=seq[i].e;
            cout<<" "<<seq[i].num;
        }
        cout<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37451344/article/details/80779507
今日推荐