zoukankan      html  css  js  c++  java
  • ZOJ Problem Set

    ZOJ Problem Set - 1076
    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

    其实用贪心也可以做不过想练练动规就动规好了

    AC代码:

    #include<iostream>
    #include<algorithm>
    #include<string.h>
    using namespace std;
    struct Gene{
    	int start,end,id;
    };
    bool cmp(Gene a,Gene b)
    {
    	if(a.start!=b.start)
    	{
    		return a.start<b.start;
    	}
    	else return a.end<b.end;
    }
    void print(int *path,Gene*g,int start,int lay)
    {
    	if(start==-1)return;
    	print(path,g,path[start],lay+1);
    	cout<<g[start].id;
    	if(lay!=0)cout<<' ';
    	else cout<<endl;
    } 
    int main()
    {
    	int n;
    	while(cin>>n&&n!=0)
    	{
    		Gene g[1001];
    		int path[1001];
    		int count[1001];
    		memset(path,-1,sizeof(path));
    		memset(count,0,sizeof(count));
    		for(int i=0;i<n;i++)
    		{
    			cin>>g[i].start>>g[i].end;
    			g[i].id=i+1; 
    		}
    		sort(g,g+n,cmp);
    		count[0]=1;
    		for(int i=1;i<n;i++)
    		{
    			for(int j=0;j<i;j++)
    			{
    				if(g[j].end<g[i].start)
    				{
    					if(count[i]<count[j])
    					{
    						count[i]=count[j];
    						path[i]=j;
    					}
    				}
    			}
    			count[i]++; 
    		}
    		int max=0;int flag;
    		for(int i=0;i<n;i++)
    		    if(max<count[i])
    		       {
    		       	max=count[i];
    		       	flag=i;
    		       }
    	   //cout<<max<<endl;
    	   print(path,g,flag,0);
    	}
    }


     

  • 相关阅读:
    ApacheCN 所有教程/文档集已备份到 Coding
    固态硬盘寿命天梯榜 2021.7
    一个垃圾佬的自我修养(一)工作站篇
    Java 向上转型
    记一次chromedriver与浏览器版本不匹配导致的问题(mac版本)
    关于C# 里面的axWindowsMediaPlayer的使用
    WCHAR的相关操作 范例 , 同时也是产生创建Sqlserver语句新表的 Sql
    C++ Win32 sokcet2.0版本 TCP 服务器
    C++ WIN 32 socket 2.0版本 TCP客户端
    数据库和传感器糅合 数据部分程序 正常运行
  • 原文地址:https://www.cnblogs.com/jackwuyongxing/p/3366501.html
Copyright © 2011-2022 走看看