HDU5748-Bellovin【最长上升子序列的变形】

来源:互联网 发布:js根据id获取对象的值 编辑:程序博客网 时间:2024/05/18 20:47


                     点击打开链接



Sample Input
311055 4 3 2 131 3 5
 

Sample Output
11 1 1 1 11 2 3

给一个序列,求出每个位置结尾的最长上升子序列;然后找一个字典序最小的这个函数值相同的子序列;


 #include <cstdio>  #include <cstring>#include<algorithm>  using namespace std;  #define INF0x3f3f3f3f  int dp[100010];    int main()  {      int t;      scanf("%d",&t);      while (t--)      {          int n,a;          scanf("%d",&n);          for(int i=0; i<=n; i++)              dp[i]=INF;          for (int i=0; i<n; i++)          {              scanf("%d",&a);              int pos=lower_bound(dp,dp+n,a)-dp;              printf (i==0?"%d":" %d",pos+1);              dp[pos]=a;              //printf("\ndp[%d]==%d\n",pos,dp[pos]);        }          printf("\n");      }      return 0;  }