poj 2533 最长上升子序列
来源:互联网 发布:淘宝号被冻结无法登录 编辑:程序博客网 时间:2024/05/01 00:32
背景:最长上升字串,自己想了好久,想出了
代码如下:
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int M = 1009, INF = 0x3fffffff;int main(void) { int n, str[1009], dp[1009]; while(scanf("%d", &n), n) { for(int i = 1; i <= n; i++) { scanf("%d", &str[i]); dp[i] = str[i]; } for(int i = n; i > 0; i--) { for(int j = n; j > i; j--) { if(str[j] > str[i]) dp[i] = max(dp[i], dp[j] + str[i]); } } int ans = -0x3fffffff; for(int i = 1; i <= n; i++) if(ans < dp[i]) ans = dp[i]; printf("%d\n", ans); } return 0;}
代码:
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int M = 1009, INF = 0x3fffffff;int main(void) { int n, x; while(~scanf("%d", &n)) { int dp[n + 2]; fill(dp, dp+n, INF); for(int i = 1; i <= n; i++) { scanf("%d", &x); for(int j = 0; j <= n; j++) { *lower_bound(dp, dp + n, x) = x; } } printf("%d\n", lower_bound(dp, dp + n, INF) - dp); } return 0;}
0 0
- poj 2533 最长上升子序列
- poj 2533 最长上升子序列
- poj 2533最长上升子序列
- poj 2533 最长上升子序列
- 最长上升子序列 nlogn poj 2533
- poj 2533 最长上升子序列
- 最长上升子序列 POJ 2533
- poj 2533 最长上升子序列
- POJ 2533 最长上升子序列
- 简单的dp@POJ(3)2533 最长上升子序列
- POJ 3903 && 1631 &&2533 最长上升子序列
- poj-2533-Longest Ordered Subsequence-最长上升子序列
- poj 2533 Longest Ordered Subsequence(LIS(最长上升子序列))
- poj 2533 数组的最长上升子序列
- 经典动态规划问题--最长上升子序列 POJ--2533
- POJ 2533 Longest Ordered Subsequence 最长上升子序列
- poj 2533 Longest Ordered Subsequence(最长上升子序列)
- POJ-2533 最长上升子序列 两种写法
- 两个堆栈实现一个队列 , 利用两个队列实现一个堆栈(Java)
- C#_Stopwatch 类
- hdoj2081手机号取后几位
- 完美解决mysql下utf-8的乱码问题
- 常用命令备忘录
- poj 2533 最长上升子序列
- 异步套接字编程之WSAEventSelect
- qt文件编译若干问题
- 编写测试计划
- Android C 层如何输出log
- 我对Java Serializable(序列化)的理解和总结
- ubuntu下mysql datetime类型错误 Out of range value for column
- RESTful API 设计指南
- VC6自带控件画坐标曲线