博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
最长递增子序列
阅读量:2194 次
发布时间:2019-05-02

本文共 1033 字,大约阅读时间需要 3 分钟。

一个是O(n^2)一个是O(logn*n)

两者都需要临时空间

#include 
using namespace std;//time complex:n^nint longest_increase_sequence(int a[], int n){ if(n==1) return n; int b[n]; int i,j; int tmp, result=1; b[0] = 1; for(i=1;i
=tmp&&a[j]<=a[i]) tmp = b[j] +1; } b[i] = tmp; if(b[i]>result) result = b[i]; } return result;}//length increased return truebool binary_replace(int a[], int n, int val){ if(n==0) { a[0] = val; return true; } int i; for(i=0;i
val) { a[i] = val; return false; } } if(i==n) { a[n] = val; return true; }}int longest_increase_sequence2(int a[], int n){ if(n<=1) return n; int b[n]; int result = 1; int len = 1; b[0] = a[0]; for(int i=1;i
>n) { for(int i=0;i
>a[i]; cout<
<

转载于:https://my.oschina.net/vintnee/blog/640482

你可能感兴趣的文章
(PAT 1096) Consecutive Factors (质因子分解)
查看>>
(PAT 1019) General Palindromic Number (进制转换)
查看>>
(PAT 1073) Scientific Notation (字符串模拟题)
查看>>
(PAT 1080) Graduate Admission (排序)
查看>>
Play on Words UVA - 10129 (欧拉路径)
查看>>
mininet+floodlight搭建sdn环境并创建简答topo
查看>>
【linux】nohup和&的作用
查看>>
Set、WeakSet、Map以及WeakMap结构基本知识点
查看>>
【NLP学习笔记】(一)Gensim基本使用方法
查看>>
【NLP学习笔记】(二)gensim使用之Topics and Transformations
查看>>
【深度学习】LSTM的架构及公式
查看>>
【python】re模块常用方法
查看>>
剑指offer 19.二叉树的镜像
查看>>
剑指offer 20.顺时针打印矩阵
查看>>
剑指offer 21.包含min函数的栈
查看>>
剑指offer 23.从上往下打印二叉树
查看>>
剑指offer 25.二叉树中和为某一值的路径
查看>>
剑指offer 60. 不用加减乘除做加法
查看>>
Leetcode C++《热题 Hot 100-14》283.移动零
查看>>
Leetcode C++《热题 Hot 100-15》437.路径总和III
查看>>