标签:super pac lse and 序列 cin htm c++ created
思路:就是按照求最长有序子序列的思路来写,跟Monkey and Banana的思路大同小异。
代码:
// Created by CAD on 2019/10/26.
#include <bits/stdc++.h>
using namespace std;
int dp[1005];
int a[1005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
while(cin>>n&&n)
{
int maxn=0;
for(int i=1;i<=n;++i)
cin>>a[i],dp[i]=a[i],maxn=max(maxn,a[i]);
for(int i=1;i<=n;++i)
for(int j=1;j<i;++j)
if(a[i]>a[j])
dp[i]=max(dp[i],dp[j]+a[i]),maxn=max(maxn,dp[i]);
cout<<maxn<<endl;
}
return 0;
}
Super Jumping! Jumping! Jumping!
标签:super pac lse and 序列 cin htm c++ created
原文地址:https://www.cnblogs.com/CADCADCAD/p/11743034.html