Pagini recente » Cod sursa (job #2783138) | Cod sursa (job #473856) | Cod sursa (job #1534764) | Cod sursa (job #2823914) | Cod sursa (job #562289)
Cod sursa(job #562289)
#include <stdio.h>
#include <string.h>
#define Dim 5001
#define INF (1<<31)-1
int v[Dim],d[Dim],use[Dim];
int main()
{
int i,j,N,min,max,pos;
freopen("subsir2.in","r",stdin);
scanf("%d",&N);
for(i=1;i<=N;i++) scanf("%d",&v[i]);
memset(d,0,sizeof(d));
memset(use,0,sizeof(use));
min=INF;
d[N]=1;
for(i=N-1;i>0;i--)
{
d[i]=N+1;
min=INF;
for(j=i+1;j<=N;j++)
{
if(v[i]<=v[j]&&min>v[j])
if(d[i]>d[j]+1) d[i]=d[j]+1;
if(v[i]<=v[j])
{
use[j]=1;
if(min>v[j]) min=v[j];
}
}
}
max=-INF;
for(i=1;i<=N;i++)
if(!use[i])
if(max>d[i])
{
max=d[i];
pos=i;
}
freopen("subsir2.out","w",stdout);
printf("%d\n",max);
return 0;
}