摘要: 题意:令到原队列的最少士兵出列后,使得新队列任意一个士兵都能看到左边或者右边的无穷远处。分析:题意一开始没看明白,A soldier see an extremity if there isn't any soldiers with a higher or equal height than his height between him and that extremity. 可知求的是递增序列,然后形成的序列应该是这样的:使剩下的队列满足a1 < a2 < a3 ... < a(i ) <=> a(i+1) > a(i+2) > .. a(n 阅读全文
posted @ 2012-08-27 11:54 pushing my way 阅读(390) 评论(0) 推荐(0) 编辑
摘要: 最长上升/不下降子序列:(LIS)有两种方法:1.动态规划,O(n^2)容易得出O(n^2)的DP递推公式:D[i]=max{D[j]}+1;(1<=j<i且E[j]<E[i])D[i]为以元素i结尾的最长子序列个数。这样经过两重循环一次遍历可以得到最长上升子序列。代码:View Code 1 #include <iostream> 2 #include <stdio.h> 3 #include <cstring> 4 using namespace std; 5 const int maxnum=100; 6 int a[maxnum], 阅读全文
posted @ 2012-08-27 11:01 pushing my way 阅读(314) 评论(0) 推荐(0) 编辑