hdu 1087 Super Jumping! Jumping! Jumping!
2017-03-15 15:14
274 查看
题意:给n个数,输出最大上升子序列的和
分析:类似最长上升子序列,dp[i]表示选i的时候最大的上升子序列和
那么 dp[i]=a[i];
for(int j=0;j<i;j++)
if(a[j]<a[i]&&dp[j]+a[i]>dp[i])
dp[i]=dp[j]+a[i];
复杂度O(n^2)
View Code
分析:类似最长上升子序列,dp[i]表示选i的时候最大的上升子序列和
那么 dp[i]=a[i];
for(int j=0;j<i;j++)
if(a[j]<a[i]&&dp[j]+a[i]>dp[i])
dp[i]=dp[j]+a[i];
复杂度O(n^2)
#include<bits/stdc++.h> using namespace std; const int maxn=1e3+5; int a[maxn],dp[maxn]; int main(){ int n; while(cin>>n&&n){ for(int i=0;i<n;i++)cin>>a[i]; int res=INT_MIN; for(int i=0;i<n;i++){ dp[i]=a[i]; for(int j=0;j<i;j++) if(a[j]<a[i]&&dp[j]+a[i]>dp[i]) dp[i]=dp[j]+a[i]; res=max(res,dp[i]); } cout<<res<<endl; } return 0; }
View Code
相关文章推荐
- HDU 1087 Super Jumping! Jumping! Jumping!
- [简单DP]Super Jumping! Jumping! Jumping! HDU - 1087
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!(基础DP)
- hdu 1087 Super Jumping! Jumping! Jumping!(水DP)
- hdu 1087Super Jumping! Jumping! Jumping!(简单的dp就是一个判断条件两个for循环,将这个量与前面出现的两进行比较)
- hdu 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping! --- DP入门之最大上升子序列
- hdu 1087 Super Jumping! Jumping! Jumping!
- hdu1087——Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- HDU-1087 Super Jumping! Jumping! Jumping!(LIS)
- HDU 1087 Super Jumping! Jumping! Jumping!
- HDU - 1087 Super Jumping! Jumping! Jumping!(最长递增子序列)
- HDU 1087 Super Jumping! Jumping! Jumping! 上升序列最大和+DP .
- HDU-1087-DP-Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping! (简单 LIS)
- HDU-1087(Super Jumping! Jumping! Jumping!)