杭电1257哪里错了啊啊啊啊 20
#include<iostream>usingnamespacestd;int*height=NULL,*dp=NULL;intn,ans;intmax(inta,int...
#include<iostream>
using namespace std;
int *height = NULL,*dp = NULL;
int n,ans;
int max(int a,int b)
{
return a > b? a : b;
}
int main(){
int i,j;
while(~scanf("%d",&n))
{
height = new int[n + 1];
dp = new int[n + 1];
memset(dp,0,sizeof(dp));
height[0] = 0;
for(i = 1;i <= n;i ++)
scanf("%d",&height[i]);
for(i = 1;i <= n;i ++)
{
for(j = 0;j < i;j ++)
if(height[j] < height[i])
dp[i] = max(dp[j] + 1,dp[i]);
}
for(ans = 0,i = 1;i <= n;i ++)
if(ans < dp[i])
ans = dp[i];
printf("%d\n",ans);
delete[] height;
delete[] dp;
}
return 0;
} 展开
using namespace std;
int *height = NULL,*dp = NULL;
int n,ans;
int max(int a,int b)
{
return a > b? a : b;
}
int main(){
int i,j;
while(~scanf("%d",&n))
{
height = new int[n + 1];
dp = new int[n + 1];
memset(dp,0,sizeof(dp));
height[0] = 0;
for(i = 1;i <= n;i ++)
scanf("%d",&height[i]);
for(i = 1;i <= n;i ++)
{
for(j = 0;j < i;j ++)
if(height[j] < height[i])
dp[i] = max(dp[j] + 1,dp[i]);
}
for(ans = 0,i = 1;i <= n;i ++)
if(ans < dp[i])
ans = dp[i];
printf("%d\n",ans);
delete[] height;
delete[] dp;
}
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询