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; }
相关文章推荐
- ZOJ 1076 Gene Assembly(LIS+路径打印 贪心)
- ZOJ --- 1076 Gene Assembly
- zoj1076-Gene Assembly
- zoj 1076 Gene Assembly
- ZOJ 1076 Gene Assembly LIS
- ZOJ1076-Gene Assembly(贪心)
- ZOJ 1076 Gene Assembly LIS
- ZOJ 1076 Gene Assembly (贪心求区间不相交问题)
- zoj 11986 LIS 二分
- Zoj 1076 Gene Assembly
- 贪心,Gene Assembly,ZOJ(1076)
- ZOJ 2278 Fight for Food(LIS)
- zoj 1108 LIS变形...睡前一水
- zoj 1076 Gene Assembly
- zoj 1076 Gene Assembly 贪心
- ZOJ 1076 Gene Assembly
- ZOJ 2136 Longest Ordered Subsequence(LIS)
- ZOJ 1076 最长上升子序列
- ZOJ 2319 Beautiful People(LIS二分法+路径输出)
- zoj1076