文章分类 - algorithms
最长上升子序列问题的几种解法
摘要:拿POJ 2533来说。Sample Input71 7 3 5 9 4 8Sample Output(最长上升/非降子序列的长度)4从输入的序列中找出最长的上升子序列(LIS)。这题一看,是一道典型的DP问题(就是动态规划),可以用dfs,深度优先遍历来解,如下代码:#include<iostream>#include<stack>using namespace std; int n;int* a;stack<int> s;int count=0;int best=0;void dfs(int i){ if(i==n) { if(s.size()>b
阅读全文
浙公网安备 33010602011771号