正文

LIS2006-08-20 21:04:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/argol/17716.html

分享到:

#include <iostream>using namespace std; #define MAXNUM 1000 char c[MAXNUM];char b[MAXNUM+1]; void solve(){     int i,first,last,mid,len;          len = 1;     i = 1;     b[1] = c[0];          while (c[i])     {         first = 1;         last = len+1;                  while (first < last)         {            mid = (first+last)>>1;            if (b[mid] < c[i])first = mid+1;            else last = mid;         }         b[first] = c[i++];         if (len < first)len = first;     }     cout << len << endl;} int main(){    cin >> c;    solve();    system("pause");    return 0;} ps:这是在看了别人的博客后自己试着去写的一个关于求最长递增子序列的程序。时间复杂度为O(nlogn).

阅读(3642) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册