Gene Assembly(贪心,简单)
1076 - Gene Assembly
时间限制: | Java: 2000 ms / Others: 2000 ms |
内存限制: | Java: 65536 KB / Others: 65536 KB |
问题描述
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.
输入说明
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.
输出说明
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.
输入样例
6 340 500 220 470 100 300 880 943 525 556 612 776 3 705 773 124 337 453 665 0
输出样例
3 1 5 6 4 2 3 1
来源
1 //提示:用结构体储存每一个exon的开始位置和结束位置,在按照结束位置从小到大排序。 2 //AC Code: 3 #include <iostream> 4 #include <cstdio> 5 #include <vector> 6 #include <algorithm> 7 8 using namespace std; 9 10 struct Exon 11 { 12 int s, e, id; 13 }E[1001]; 14 15 bool operator < (const Exon& a, const Exon& b) 16 { 17 return a.e < b.e; 18 } 19 20 int main() 21 { 22 int n, EndPos; 23 while(scanf("%d", &n) && n) 24 { 25 vector<int> v; 26 for(int i = 0; i < n; i++) 27 { 28 scanf("%d %d", &E[i].s, &E[i].e); 29 E[i].id = i + 1; 30 } 31 sort(E, E + n); 32 for(int i = 0, EndPos = 0; i < n; i++) 33 { 34 if(EndPos < E[i].s) 35 { 36 v.push_back(E[i].id); 37 EndPos = E[i].e; 38 } 39 } 40 vector<int>::iterator it = v.begin(); 41 printf("%d", *it); 42 for(it++; it != v.end(); ++it) 43 printf(" %d", *it); 44 puts(""); 45 } 46 return 0; 47 }