Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int dp[100005][10];
- int main()
- {
- int n;
- cin>>n;
- vector<int>v;
- for(int i=0; i<n; i++){
- int a;
- cin>>a;
- v.push_back(a);
- }
- int result=0;
- for(int i=0; i<=n; i++){
- for(int j=0; j<=3; j++){
- dp[i][j]=-1;
- }
- }
- dp[0][0]=0;
- for(int i=0; i<n; i++){
- for(int previous_activity=0; previous_activity<=3; previous_activity++){
- if(v[i]==0){
- dp[i+1][0]=max(dp[i+1][0], dp[i][previous_activity]);
- }
- if(v[i]==1){
- if(previous_activity!=1){
- dp[i+1][1]=max(dp[i+1][1], dp[i][previous_activity]+1);
- }
- }
- dp[i+1][0]=max(dp[i+1][0], dp[i][previous_activity]);
- if(v[i]==2){
- if(previous_activity!=2){
- dp[i+1][2]=max(dp[i+1][2], dp[i][previous_activity]+1);
- }
- }
- dp[i+1][0]=max(dp[i+1][0], dp[i][previous_activity]);
- if(v[i]==3){
- if(previous_activity!=2){
- dp[i+1][2]=max(dp[i+1][2], dp[i][previous_activity]+1);
- }
- if(previous_activity!=1){
- dp[i+1][1]=max(dp[i+1][1], dp[i][previous_activity]+1);
- }
- dp[i+1][0]=max(dp[i+1][0], dp[i][previous_activity]);
- }
- }
- }
- for(int i=0; i<=n; i++){
- for(int j=0; j<=3; j++){
- result=max(result, dp[i][j]);
- }
- }
- cout<<result;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement