Uva 481 - What Goes Up
来源:互联网 发布:biz域名火吗 编辑:程序博客网 时间:2024/06/05 05:20
终于把这个nlgn的LIS搞定了==
学习了stl迭代器的做法
lower_bound实在是给力==
dp输出是叉姐教的==
感谢啦
原本会nlgn不过不会输出方案,现在会了
原来并不难--
#include<stdio.h>#include<vector>#define SMAX 1000010#include<algorithm>int n,a[SMAX];int dp[SMAX];int ok[SMAX];std::vector<int>f;std::vector<int>::iterator pf;int at[SMAX],pat;int max(int a,int b){if(a>b)return a;return b;}int main(){n=0;f.clear();int i,j;while(scanf("%d",&a[++n])!=EOF);n--;dp[1]=1;f.push_back(a[1]);for(i=2;i<=n;i++){pf = lower_bound( f.begin(), f.end(), a[i] );int k=pf-f.begin();//printf("%d\n",k);if(pf==f.end()){f.push_back(a[i]);dp[i]=f.size();}else {*pf=a[i];//at[k]=i;dp[i]=k+1;}//f.push_back(a[i]);//sort(f.begin(),f.end());//for(j=0;j<f.size();j++)printf("%d ",f[j]);printf("\n");}int res=1;for(i=1;i<=n;i++)res=max(dp[i],res);int pes=1;for(i=1;i<=n;i++)if(dp[i]==res)pes=i;printf("%d\n-\n",res);for(i=1;i<=n;i++)ok[i]=0;ok[pes]=1;for(i=pes-1;i>=1;i--){if(dp[i]==res-1&&a[i]<a[pes]){pes=i;ok[pes]=1;res--;}}for(i=1;i<=n;i++)if(ok[i])printf("%d\n",a[i]);//return main();return 0;}
- UVa 481 - What Goes Up
- Uva 481 - What Goes Up
- UVA 481 what goes up
- UVa:481 What Goes Up
- UVa481 - What Goes Up
- uva481 What Goes Up
- UVa481 What Goes Up
- UVA 481 What Goes Up LIS+nlog(n)算法,打印路径
- what's up
- what's up
- USA : Tandy Leather's retail leathercraft segment goes up 38%
- What goes in to the message of a transaction signature?
- What's up with BeginInvoke?
- UVa 270 - Lining Up
- UVa 270 - Lining Up
- uva 270 - Lining Up
- UVa 270 - Lining Up
- UVa 270 - Lining Up
- Ubuntu下tar.gz文件安装方法
- 经典算法研究系列:五、红黑树算法的实现与剖析
- 每日总结:sql 转换为int时发生算术溢出错误、DatePart()、DateAdd()、DateDiff()函数、Case when then
- 致访客
- 网站的LOGO尺寸大小参考
- Uva 481 - What Goes Up
- 游戏开发团队人力资源分配
- .Net记忆围棋益智小游戏
- CMOS电平和TTL电平
- 关于作者
- SQLLite数据库学习
- oracle 中的null
- 系统性能检测工具
- IOS 类方法与实例方法的区别