Super Jumping! Jumping! Jumping! HDU - 1087
生活随笔
收集整理的這篇文章主要介紹了
Super Jumping! Jumping! Jumping! HDU - 1087
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Super Jumping! Jumping! Jumping! HDU - 1087
題意:
給定一條長度為n的序列,其中一定存在一條元素和最大的嚴(yán)格上升子序列,求這條序列的元素和。
題解:
最長上升序列模板題
代碼:
#include<bits/stdc++.h> #define debug(a,b) printf("%s = %d\n",a,b); typedef long long ll; using namespace std;inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();//s=(s<<3)+(s<<1)+(ch^48);return s*w; } const int maxn=3e3+9; int a[maxn]; int dp[maxn]; int main() {int n;while(cin>>n){memset(dp,0,sizeof(dp));if(n==0)break;for(int i=1;i<=n;i++)cin>>a[i];int maxx=0;for(int i=1;i<=n;i++){dp[i]=a[i];for(int j=1;j<=i;j++){if(a[j]<a[i]) dp[i]=max(dp[j]+a[i],dp[i]);}maxx=max(dp[i],maxx);}cout<<maxx<<endl;} }總結(jié)
以上是生活随笔為你收集整理的Super Jumping! Jumping! Jumping! HDU - 1087的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 腾讯口碑最好的游戏腾讯游戏最好玩的
- 下一篇: G List it all