poj 1887 Testing the CATCHER(最长递增子序列)
2011-10-02 15:05
477 查看
题意:给你一些数找到最长递减子序列
思路:跟nyoj 214 差不多,只不过这儿是单调递减
思路:跟nyoj 214 差不多,只不过这儿是单调递减
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; #define maxN 40000 int f[maxN],so[maxN],key[maxN],n; bool cmp(int &x,int &y) { return x>y; } int low_bun(int l,int r,int x) { if(l==r)return l; int mid=(l+r)/2; if(so[mid]<=x)return low_bun(l,mid,x); else return low_bun(mid+1,r,x); } int low(int x){return x&(-x);} int get_max(int x) { int maxx=0; while(x!=0){ maxx=max(maxx,key[x]); x-=low(x); } return maxx; } void update(int x) { int m=x; while(x<n+1){ if(key[m]>=key[x]) key[x]=key[m]; else break; x+=low(x); } } int main() { int k=1; while(scanf("%d",&f[1])&&f[1]!=-1) { memset(key,0,sizeof(key)); n=2; so[0]=0x0fffff,so[1]=f[1]; while(scanf("%d",&f )&&f !=-1) so =f[n++]; sort(so,so+n,cmp); int maxx=0; for(int i=1;i<n;i++) { int m=low_bun(1,n-1,f[i]); key[m]=get_max(m-1)+1; maxx=max(maxx,key[m]); update(m); } printf("Test #%d:\n maximum possible interceptions: %d\n\n",k++,maxx); } }
相关文章推荐
- POJ 1887-Testing the CATCHER(dp_最长下降子序列)
- Testing the CATCHER - POJ 1887 最长递减子序列
- POJ 1887 —— Testing the CATCHER 最长下降子序列
- POJ-1887-Testing the CATCHER【最长不上升子序列nlogn】
- POJ 1887 Testing the CATCHER(最长递减子序列)
- POJ 1887 Testingthe CATCHER (LIS:最长下降子序列)
- POJ-1887 Testing the CATCHER(dp,最长下降子序列)
- poj 1887 Testing the CATCHER_最长上升子序列
- POJ-1887 Testing the CATCHER(dp,最长下降子序列)
- poj 1887 Testing the CATCHER_最长上升子序列
- poj 1887 Testing the CATCHER (最长不上升子序列)
- POJ 1887 Testing the CATCHER(最长下降子序列)
- Pku1887----Testing the CATCHER (经典动态规划题:最长下降子序列),,,,,捎带pku2533---Longest Ordered Subsequence
- POJ 1887 Testing the CATCHER 最长不下降序列(LIS)问题
- POJ 1887 Testing the CATCHER(最长非升子序列)
- POJ 1887 Testing the CATCHER[最长非升子序列O(nlog(n))]
- POJ-1887-Testing the CATCHER-最长递减子序列-DP动态规划
- poj 1887 Testing the CATCHER 最长不升子序列
- 【最长非升子序列】北大 POJ 1887 Testing the CATCHER
- POJ-1887-Testing the CATCHER