-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVacations.cpp
More file actions
76 lines (66 loc) · 1.41 KB
/
Vacations.cpp
File metadata and controls
76 lines (66 loc) · 1.41 KB
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
68
69
70
71
72
73
74
75
76
//
// Created by Kiam on 25-Aug-20.
// R = 0; C = 1; G = 2;
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
vector<int> v;
int n;
ll dp[105][10];
int f(int s, int i)
{
int val = 0;
if(dp[i][s]!=-1) return dp[i][s];
if(i==n)
{
return dp[i][s] = 0;
}
if(v[i]==0)
{
return dp[i][s] = val = max(val, f(0, i+1));
}
if(v[i]==1)
{
if(s!=1)
{
return dp[i][s] = val = max(val, max(f(1, i+1)+1, f(0, i+1)));
}
else
return dp[i][s] = val = max(val, f(0, i+1));
}
if(v[i]==2)
{
if(s!=2)
{
return dp[i][s] = val = max(val, max(f(2, i+1)+1, f(0, i+1)));
}
else
return dp[i][s] = val = max(val, f(0, i+1));
}
if(v[i]==3)
{
if(s==2)
{
return dp[i][s] = val = max(val, max(f(1, i+1)+1,f(0, i+1)));
}
else if(s==1)
{
return dp[i][s] = val = max(val, max(f(2, i+1)+1, f(0, i+1)));
}
else
return dp[i][s] = val = max(val, max(f(0, i+1), max(f(1, i+1)+1,f(2, i+1)+1)));
}
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(nullptr);
memset(dp, -1, sizeof(dp));
cin>>n;
for(int i=0; i<n; i++)
{
int x; cin>>x;
v.push_back(x);
}
cout<<n-f(4, 0)<<"\n";
}