Gene Assembly
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
题目类型:贪心
算法分析:这是一道经典的任务调度问题,先按任务的结束时间递减排序,再逐个选择,选择活动的起始时间大于已选择活动的结束时间,最后输出选择的活动的id即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
#include <iostream> #include <fstream> #include <algorithm> #include <iomanip> #include <cstring> #include <cstdio> #include <cmath> #include <map> #include <string> #include <vector> #include <stack> #include <queue> #include <set> #include <list> #include <ctime> using namespace std; struct Node { int x, y, flag; }; bool Cmp (Node a, Node b) { return a.y < b.y; } Node ans[1666]; int output[1666]; int main() { // ifstream cin ("aaa.txt"); // freopen ("aaa.txt", "r", stdin); int n; while (cin >> n) { if (n == 0) break; int i; for (i = 0; i < n; i++) { cin >> ans[i].x >> ans[i].y; ans[i].flag = i + 1; } sort (ans, ans + n, Cmp); int len = 0; output[len++] = ans[0].flag; int ps = ans[0].y; for (i = 1; i < n; i++) { if (ps <= ans[i].x) { ps = ans[i].y; output[len++] = ans[i].flag; } } for (i = 0; i < len - 1; i++) cout << output[i] << " "; cout << output[i] << endl; } return 0; } |
- « 上一篇:zoj1061
- zoj1082:下一篇 »