标签:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #define ll long long using namespace std; ll n,num,ans,hou[10000000],f[10000000],c[10000000],size; struct node { ll l,r,data; }t[10000000]; void Hou(ll p) { if(p) { Hou(t[p].l); Hou(t[p].r); if(t[p].data) hou[++num]=t[p].data; } } ll lon() { ll i,x; for(i=1;i<=num;i++) { x=hou[i]; if(x>c[size]) { c[++size]=x; continue; } int mm,l=0,r=size,ans; while(l<=r) { mm=(l+r)/2; if(x>c[mm]) { ans=mm; l=mm+1; } else r=mm-1; } c[ans+1]=x; } return size; } int main() { scanf("%lld",&n); ll x; for(ll i=1;i<=n;i++) { ll sum=1; while(~scanf("%lld",&x)) { ++num; sum++; t[num].data=x; t[num].l=num*2; t[num].r=num*2+1; if(sum>pow(2,i-1))break; } } num=0; Hou(1); ans=lon(); printf("%lld\n",num-ans); return 0; }
标签:
原文地址:http://www.cnblogs.com/yanlifneg/p/5479697.html