您的位置:首页 > 其它

ZOJ 1076 Gene Assembly(LIS)

2013-05-01 08:51 274 查看
首先对exon排序,再DP,保存路径输出.

#include <iostream>
#include <cstdio>
#include <memory.h>
#include <algorithm>
using namespace std;
const int maxn=1001;
struct exon{
int beg,end,id;
bool operator<(const exon &rhs)const{
return beg<rhs.beg||(beg==rhs.beg&&end<rhs.end);
}
}es[maxn];
int father[maxn],dp[maxn],n;
void printPath(int v){
if(v==father[v]){
printf("%d",es[v].id);
return;
}
printPath(father[v]);
printf(" %d",es[v].id);
}
int main(){
while (scanf("%d",&n)&&n){
for (int i=1;i<=n;++i){
scanf("%d%d",&es[i].beg,&es[i].end);
if(es[i].beg>es[i].end){
swap(es[i].beg,es[i].end);
}
es[i].id=i;
}
sort(es+1,es+n+1);
int maxv=0,maxi=0;
for (int i=1;i<=n;++i){
int ma=0,fa=i;
for (int j=1;j<=i-1;++j){
if(es[i].beg>es[j].end&&dp[j]>ma){
ma=dp[j];
fa=j;
}
}
dp[i]=ma+1;
father[i]=fa;
if(maxv<dp[i]){
maxv=dp[i];
maxi=i;
}
}
printPath(maxi);
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: