poj 1887dp最长下降子序列

xiaoxiao2021-02-28  86

#include<cstdio> #include<cstring> int dp[36000]; int d[36000]; int main() { int t=1; while(~scanf("%d",&d[0])&&d[0]!=-1) { int len=1; while(~scanf("%d",&d[len])&&d[len]!=-1) { len++; } dp[1]=d[0]; int tot=1; for(int i=1;i<len;i++) { if(d[i]<=dp[tot]) { tot++; dp[tot]=d[i]; } else { int l=1; int r=tot; while(l<r) { int m=(l+r)>>1; if(dp[m]>d[i]) l=m+1; else r=m; } dp[r]=d[i]; } } printf("Test #%d:\n",t++); printf(" maximum possible interceptions: %d\n\n",tot); } }
转载请注明原文地址: https://www.6miu.com/read-54375.html

最新回复(0)