DP简单问题联系--最长递增子序列+最长公共子序列等
今天重温了一下dp问题,发现自己两个礼拜不写题目就什么都不会了。。。心态爆炸,感觉去考试怕是要gg了。。。
不过今天总结一下写的题目,全部都是基础的dp问题
第一个是
求最长不下降子序列的长度
第一行为n,表示n个数 第二行n个数
最长不下降子序列的长度
N小于5000 for each num < =maxint
样例输入
3
1 2 3
样例输出
3
//
// Created by 陈平 on 2018/7/8.
// #include "iostream"
using namespace std; int main(){
int num[];
int dp[];
int n;
cin>>n;
for (int i = ; i <=n ; ++i) {
cin>>num[i];
dp[i] = ;
}
int maxx = ;
for (int j = ; j <=n ; ++j) {
maxx = ;
for (int i = ; i <j ; ++i) {
if(num[i]<num[j]) maxx = max(dp[i]+,maxx);
}
dp[j] = maxx;
}
int flag = -; for (int k = ; k <=n ; ++k) {
if(dp[k]>flag) {
flag = dp[k];
} }
cout<<flag;
// for (int l = 1; l <=n ; ++l) {
// cout<<dp[l];
// }
}
难度不大,思想也比较简单。
DP简单问题联系--最长递增子序列+最长公共子序列等的更多相关文章
- DP_最长公共子序列/动规入门
学自:https://open.163.com/movie/2010/12/L/4/M6UTT5U0I_M6V2U1HL4.html 最长公共子序列:(本文先谈如何求出最长公共子序列的长度,求出最长公 ...
- dp之最长递增、公共子序列总结
1.最长递增子序列模板poj2533(时间复杂度O(n*n)) #include<iostream> #include<stdio.h> #include<string. ...
- dp之最长递增子序列模板poj3903
最长递增子序列,Longest Increasing Subsequence 下面我们简记为 LIS.排序+LCS算法 以及 DP算法就忽略了,这两个太容易理解了. 假设存在一个序列d[1..9] = ...
- 动态规划(DP),最长递增子序列(LIS)
题目链接:http://poj.org/problem?id=2533 解题报告: 状态转移方程: dp[i]表示以a[i]为结尾的LIS长度 状态转移方程: dp[0]=1; dp[i]=max(d ...
- 简单Dp----最长公共子序列,DAG最长路,简单区间DP等
/* uva 111 * 题意: * 顺序有变化的最长公共子序列: * 模板: */ #include<iostream> #include<cstdio> #include& ...
- Longest Increasing Subsequences(最长递增子序列)的两种DP实现
一.本文内容 最长递增子序列的两种动态规划算法实现,O(n^2)及O(nlogn). 二.问题描述 最长递增子序列:给定一个序列,从该序列找出最长的 升序/递增 子序列. 特点:1.子序列不要 ...
- [DP]最长递增子序列
#include <iostream> #include <limits.h> #include <vector> #include <algorithm&g ...
- HDU-1160-FatMouse's Speed(DP, 最长递增子序列)
链接: https://vjudge.net/problem/HDU-1160 题意: FatMouse believes that the fatter a mouse is, the faster ...
- 求解最长递增子序列(LIS) | 动态规划(DP)+ 二分法
1.题目描述 给定数组arr,返回arr的最长递增子序列. 2.举例 arr={2,1,5,3,6,4,8,9,7},返回的最长递增子序列为{1,3,4,8,9}. 3.解答 ...
- [程序员代码面试指南]最长递增子序列(二分,DP)
题目 例:arr=[2,1,5,3,6,4,8,9,7] ,最长递增子序列为1,3,4,8,9 题解 step1:找最长连续子序列长度 dp[]存以arr[i]结尾的情况下,arr[0..i]中的最长 ...
随机推荐
- css常用总结
1.固定一个层在页面的位置,不受滚动条影响, 属性position:fixed,如: .tbar{ height:200px;width:60px;background-color:#666;posi ...
- 九度OJ 1098:字母统计 (计数)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3720 解决:1809 题目描述: 输入一行字符串,计算其中A-Z大写字母出现的次数 输入: 案例可能有多组,每个案例输入为一行字符串. 输 ...
- Asynchronous programming with async and await (C#)
Asynchronous Programming with async and await (C#) | Microsoft Docs https://docs.microsoft.com/en-us ...
- Apache JServ Protocol
ajp_百度百科 https://baike.baidu.com/item/ajp/1187933 AJP(Apache JServ Protocol)是定向包协议.因为性能原因,使用二进制格式来传输 ...
- shapes
接口 shape package shape; public abstract interface shape { public abstract void Draw(); public abstra ...
- querySelectorAll和getElementsBy 系列比较
querySelectorAll 相比下面这些方法有什么区别? (1)getElementsByTagName (2)getElementsByClassName (3)getElementsByNa ...
- jquery中attr和prop的区别—判断复选框选中状态
最近项目中需要用jquery判断input里checkbox是否被选中,发现用attr()获取不到复选框改变后的状态,最后查资料发现jQuery 1.6以后新增加了prop()方法,借用官方的一段描述 ...
- BestCoder Round #92 1002 Count the Sheep —— 枚举+技巧
题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1002 题解: 做题的时候只是想到 ...
- iap 应用内购买相关的解释
应用范围app Store Review Guidelines : https://developer.apple.com/app-store/review/guidelines/ 中 11.12 ...
- 数学题--On Sum of Fractions
题目链接 题目意思: 定义v(n)是不超过n的最大素数, u(n)是大于n的最小素数. 以分数形式"p/q"输出 sigma(i = 2 to n) (1 / (v(i)*u(i) ...