HDU1087(最长上升子序列DP)
来源:互联网 发布:苹果录屏用什么软件 编辑:程序博客网 时间:2024/04/30 05:49
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087
解题思路:
i < j 时 , dp[ i ] = max( dp[ j ] + a[ i ] , a[ i ] ) 。记录保存最大的dp[ i ] 值即可。dp[ i ] 代表从1到 i 的最大上升子序列的和,里层循环为dp[ i ]做更新,寻找1到 i 区间内的最大上升子序列和,从而使得其具有局部最优子结构。
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;const int maxn = 10001;int a[maxn];int dp[maxn];int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif std::ios::sync_with_stdio(false); std::cin.tie(0); int n; while(cin >> n) { if(n == 0) break; for(int i = 0 ; i < n ; i ++) cin >> a[i]; int maxx = -INF; for(int i = 0 ; i < n ; i ++) { dp[i] = a[i]; if(dp[i] > maxx) maxx = dp[i]; for(int j = 0 ; j < i ; j ++) { if(a[i] > a[j] && dp[j] + a[i] > dp[i]) { dp[i] = dp[j] + a[i]; if(dp[i] > maxx) maxx = dp[i]; } } } cout << maxx << endl; }}
0 0
- HDU1087(最长上升子序列DP)
- hdu1087最长(最大)上升子序列
- HDU1087 最长上升子序列
- HDU1087 最长上升子序列
- HDU1087最长上升子序列
- HDU1087最长上升子序列
- HDU1087 Super Jumping! Jumping! Jumping!【最长上升子序列+DP】
- HDU1087 最长上升子序列加强版
- hdu1087(最长上升子序列求和)
- poj2533&&hdu1087 最长上升子序列问题
- hdu1087最长递增子序列dp
- 最长上升子序列 (dp)
- 最长公共上升子序列 (dp)
- 最长上升子序列(DP)
- 最长上升子序列LIS(dp)
- 最长上升子序列(DP+模板)
- YTU3135--最长上升子序列(dp)
- 最长上升子序列(dp)
- 在iOS开发中使用FMDB
- jvm内存调优
- StageFright框架(二)和OpenMAX的運作
- HPUoj题目1062 能量项链(区间dp)
- Android Studio简单设置
- HDU1087(最长上升子序列DP)
- ANDROID内存优化(大汇总——全)
- 使用PageHeap.EXE或GFlags.EXE检查内存越界错误(转)
- onSaveInstanceState执行时机
- java中異常(一)
- 基础算法系列(十九)排序算法之内省排序
- APUE第三章3.2习题分析
- win 7和Ubuntu 14.04双系统安装与卸载
- 安装使用protobuf,及使用C++编写多线程通信