求大神帮忙!(눈_눈)

心力交瘁,搞了好几个小时就是通不过。求大神看看代码哪错了
#include<stdio.h>
#include<stdlib.h>
int sta[150];
int order[150];
int result[150];
int up(int low,int high);
int down(int low,int high);
int main(void)
{
int n=0,i,answer=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&sta[i]);
}
for(i=1;i<=n;i++)
{
order[i]=up(1,i)+down(i,n)-1;
}
for(i=1;i<=n;i++)
{
if(answer<order[i]) answer=order[i];
}
printf("%d",n-answer);
}
int up(int low,int high)
{
int i,j;
result[low]=1;
if(low==high) return 1;
for(i=low+1;i<=high;i++)
{
int temp=0;
for(j=low;j<i;j++)
{
if(sta[i]>sta[j])
{
if(temp<result[j]) temp=result[j];
}
}
result[i]=temp+1;
}
return result[high];
}
int down(int low,int high)
{
int i,j;
result[low]=1;
if(low==high) return 1;
for(i=low+1;i<=high;i++)
{
int temp=0;
for(j=low;j<i;j++)
{
if(sta[i]<sta[j])
{
if(temp<result[j]) temp=result[j];
}
}
result[i]=temp+1;
}
return result[high];
}

0 条评论

目前还没有评论...

信息

ID
1098
难度
5
分类
动态规划 | LIS 点击显示
标签
递交数
12819
已通过
4882
通过率
38%
被复制
20
上传者