入门dp;
求不连续最大上升子串
方程自己看代码
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int price[1001];
__int64 dp[1001];
int max(int x,int y)
{
return x>y?x:y;
}
bool cmp(__int64 x,__int64 y)
{
return x>y;
}
int main()
{
int n;
while (scanf("%d",&n)!=EOF && n!=0)
{
memset(price,0,sizeof(price));
memset(dp,0,sizeof(dp));
for (int i=1; i<=n; ++i)
scanf("%d",price+i);
for (int i=1; i<=n; ++i)
dp[i]=price[i];
//dp[1]=price[1];
for (int i=1; i<=n; ++i)
{
for (int j=1; j<i; ++j)
{
if (price[j]<price[i])
dp[i]=max(dp[i],dp[j]+price[i]);
}
}
sort(dp+1,dp+n+1,cmp);
cout<<dp[1]<<endl;
}
}