HDU 1087 Super Jumping! Jumping! Jumping!
2014-05-05 17:53
260 查看
动态规划
最大递增子段和
状态转移方程 dp[i]=max(dp[j])+v[i] 0<=j<=i 且v[j]<v[i]
#include<bits/stdc++>
using namespace std;
long long v[1020],dp[1020];
int main()
{
int N;
while(scanf("%d",&N)==1&&N)
{
memset(dp,0,sizeof(dp));
for(int i=1;i<=N;i++)
scanf("%I64d",&v[i]);
for(int i=1;i<=N;i++)
{
long long maxv=0;
for(int j=0;j<=i-1;j++)
{
if(v[j]<v[i]&&dp[j]>maxv)
maxv=dp[j];
}
dp[i]=maxv+v[i];
}
long long ans=0;
for(int i=1;i<=N;i++)
{
if(dp[i]>ans)
ans=dp[i];
}
printf("%I64d\n",ans);
}
return 0;
}
最大递增子段和
状态转移方程 dp[i]=max(dp[j])+v[i] 0<=j<=i 且v[j]<v[i]
#include<bits/stdc++>
using namespace std;
long long v[1020],dp[1020];
int main()
{
int N;
while(scanf("%d",&N)==1&&N)
{
memset(dp,0,sizeof(dp));
for(int i=1;i<=N;i++)
scanf("%I64d",&v[i]);
for(int i=1;i<=N;i++)
{
long long maxv=0;
for(int j=0;j<=i-1;j++)
{
if(v[j]<v[i]&&dp[j]>maxv)
maxv=dp[j];
}
dp[i]=maxv+v[i];
}
long long ans=0;
for(int i=1;i<=N;i++)
{
if(dp[i]>ans)
ans=dp[i];
}
printf("%I64d\n",ans);
}
return 0;
}
相关文章推荐
- Hdu 1087 Super Jumping! Jumping! Jumping! (DP)
- 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!(简单dp)
- hdu - 1087 - Super Jumping! Jumping! Jumping!
- HDU-1087(Super Jumping! Jumping! Jumping!)(LCS)
- HDU 1087 Super Jumping! Jumping! Jumping!(最大的上升子序列的和)(不是最长)(易混淆)
- hdu 1087 Super Jumping! Jumping! Jumping!(dp:上升子序列最大和)
- HDU_1087_Super Jumping! Jumping! Jumping!_dp
- HDU 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping! -- 简单动态规划
- hdu 1087 Super Jumping! Jumping! Jumping!
- 【最长上升子序列】HDU 1087——Super Jumping! Jumping! Jumping!
- 【最长上升子序列】HDU 1087——Super Jumping! Jumping! Jumping!
- HDU_1087_SuperJumping!Jumping!Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!(基础DP,最大上升子序列和)