hdu 1257 最长上升子序列问题
2015-04-22 21:18
225 查看
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257
dp[i]表示以i结尾的最长上升子序列的长度
转移方程dp[i] = max(dp[i],dp[j]+1)
代码:
dp[i]表示以i结尾的最长上升子序列的长度
转移方程dp[i] = max(dp[i],dp[j]+1)
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define M 100009 #define INF 0x3f3f3f3f int a[M]; int dp[M]; //代表以i结尾的最长的上升子序列的长度 int main() { int n; while(scanf("%d",&n)==1) { for(int i = 0;i < n;i++) scanf("%d",&a[i]); int ans = -INF; for(int i = 0;i < n;i++) { dp[i] = 1; //每个都初始化为1 for(int j = 0;j < i;j++) { if(a[j]<a[i]) dp[i] = max(dp[i],dp[j]+1); //选取当前的最优解 //一开始直接写成了dp[i] = dp[j]+1 ;还是图样。。 反例6个数 1 4 6 8 3 9 以最后一个结尾的应该是5而不是2 } ans = max(ans,dp[i]); } printf("%d\n",ans); } return 0; }
相关文章推荐
- HDU 1257 最少拦截系统(最长上升子序列)
- HDU-1257--最少拦截系统--最长上升子序列
- hdu 1087最长上升子序列和问题
- HDU 46DP (7 01背包问题 8 最长上升子序列O(n*n))
- HDU 1257(贪心;动态规划(最长上升子序列))
- HDU 1257 最少拦截系统(最长上升子序列+贪心)
- HDU 1257 最少拦截系统(最长上升子序列+贪心)
- HDU-1257 最少拦截系统 贪心/DP 最长上升子序列的长度==最长不上升子序列的个数?
- HDU-4521 小明系列问题——小明序列 间隔限制最长上升子序列
- HDU 1257 最少拦截系统(最长上升子序列+贪心)
- 【hdu 1257】最少拦截系统(LIS最长上升子序列)
- HDU 3998 Sequence(经典问题,最长上升子序列)
- HDU 1257 最长上升子序列
- HDU 1257 最少拦截系统(最长上升子序列+贪心)
- hdu 5421 小明系列问题——小明序列(LIS最长上升子序列)
- 每日三题-Day3-C(HDU 1257 最少拦截系统 最长上升子序列O(nlogn) )
- HDU1160 FatMouse's Speed 带路径的最长上升子序列问题
- HDU 1257 最少拦截系统(最长上升子序列+贪心)
- 最少拦截系统(hdu-1257)(最长上升子序列)
- HDU 1257 最少拦截系统(最长上升子序列+贪心)