-
Notifications
You must be signed in to change notification settings - Fork 0
/
Murcia’s Skyline.cpp
68 lines (64 loc) · 1.29 KB
/
Murcia’s Skyline.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
61
62
63
64
65
66
67
#include<bits/stdc++.h>
using namespace std;
#define lm 1000
int hight[lm],width[lm],i_dp[lm],d_dp[lm],i_dir[lm],d_dir[lm];
int n;
int is(int u)
{
if(i_dp[u]!=-1)
return i_dp[u];
int length=0;
for(int v=u+1;v<n;v++)
{
if(hight[v]>hight[u])
{
int x=is(v);
if(x>lenght)
length=x;
}
}
return i_dp[u]=length+width[u];
}
int ds(int u)
{
if(d_dp[u]!=-1)
return d_dp[u];
int length=0;
for(int v=u+1;v<n;v++)
{
if(hight[v]<hight[u])
{
int x=ds(v);
if(x>length)
length=x;
}
}
return d_dp[u]=length+width[u];
}
int main()
{
int t,i,j;
cin>>c;
for(i=1;i<=n;i++)
{
cin>>n;
for(j=0;j<n;j++)
cin>>hight[j];
for(j=0;j<n;j++)
cin>>width[j];
memset(i_dp,-1,sizeof i_dp);
memset(d_dp,-1,sizeof d_dp);
int i_lenght=0,d_length=0,x,y;
for(j=0;j<n;j++)
{
x=is(j);
y=ds(j);
if(i_lenght<x)
i_lenght=x;
if(d_length<y)
d_length=y;
}
cout<<"Case "<<i<<". Increasing ("<<i_lenght<<")";
cout<<". Decreasing ("<<d_length<<")."<<endl;
}
}