HDU-1087(最长递增序列)
2012-08-16 10:17
288 查看
其实一开始就有思路的,但是,我一看,算法是两重循环..虽然不超时,觉得还是不好,觉得DP应该不会这样吧...
别了我很长时间,最后还是想去试试吧,,试了一试,还真是这么算..晕了.
贴出代码:
别了我很长时间,最后还是想去试试吧,,试了一试,还真是这么算..晕了.
贴出代码:
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> int a[1005]; int dp[1005]; int max(int a,int b) { return a>=b?a:b; } int main() { int N; while(scanf("%d",&N),N) { a[0]=0; dp[0]=0; for(int i=1;i<=N;i++) scanf("%d",a+i); dp[1]=a[1]; int maxi=0; for(i=2;i<=N;i++) { int t=0; for(int j=i-1;j>=1;j--) { if(a[i]>a[j]) t=max(dp[j],t); } dp[i]=t+a[i]; if(maxi<dp[i]) maxi=dp[i]; } printf("%d\n",maxi); } return 0; }
相关文章推荐
- hdu 1087 LIS 最长递增子序列的值
- hdu 1087 Super Jumping! Jumping! Jumping!(dp+最长递增序列)
- hdu 1087 Super Jumping! Jumping! Jumping!(dp+最长递增序列)
- HDU 1087--Super Jumping! Jumping! Jumping!【最长递增子序列的和】
- [LIS_最长递增子序列]-hdu 1087 Super Jumping!
- hdu 5256 序列变换 求最少改变次数使序列变为递增 最长不下降子序列
- HDU 1087 Super Jumping! Jumping! Jumping! (最长上升子序列求和)【最长序列求和类模板】
- hdu 1069 Monkey and Banana(最长递增子序列的变形)
- HDU 3308 LCIS (线段树&&最长递增子序列长度)
- 最长单调递增子序列 poj 2544 || HDU 3998
- HDU 1069&&HDU 1087 (DP 最长序列之和)
- HDU 4521 小明系列问题——小明序列【dp+线段树优化||最长递增序列】
- HDU 3308 LCIS 最长连续递增序列+数据结构+线段树+单点更新
- [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)
- hdu 1087 Super Jumping! Jumping! Jumping! 最长上升子序列的变形
- HDU 1423 Greatest Common Increasing Subsequence 最长公共递增序列
- [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)
- hdu 5748 Bellovin (最长递增子序列 二分查找)
- [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)
- HDU 1087 Super Jumping! Jumping! Jumping!(最长上升子序列,dp)