-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path63ChorusFormationDP1131.cpp
61 lines (54 loc) · 1.08 KB
/
63ChorusFormationDP1131.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<iostream>
using namespace std;
int max_num(int a,int b)
{
return a>b?a:b;
}
int dp1[101],dp2[101],height[101];
int main()
{
int n;
while(cin>>n)
{
int i,j,tmax;
for( i=1; i<=n; i++)
{
cin>>height[i];
dp1[i]=1;
dp2[i]=1;
}
for( i=1; i<=n; i++)
{
tmax=1;
for( j=1; j<i; j++)
{
if(height[i]>height[j])
{
tmax=max_num(tmax,dp1[j]+1);
}
}
dp1[i]=tmax;
}
for(i=n; i>=1; i--)
{
tmax=1;
for(j=n; j>i; j--)
{
if(height[i]>height[j])
{
tmax=max_num(tmax,dp2[j]+1);
}
}
dp2[i]=tmax;
}
int ans=1;
for(i=1; i<=n; i++)
{
// cout<<dp1[i]<<" "<<dp2[i]<<endl;
ans=max_num(ans,dp1[i]+dp2[i]-1);
}
ans=n-ans;
cout<<ans<<endl;
}
return 0;
}