codeforces #round363 div2.C-Vacations (DP)

题目链接:http://codeforces.com/contest/699/problem/C

dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2。

#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
int dp[105][3];
int main()
{
    int n;
    scanf("%d",&n);
    memset(dp,INF,sizeof(dp));
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for(int i = 1 ;i <= n ;i++)
    {
        int x;
        scanf("%d",&x);
        dp[i][0] = min(dp[i-1][0],min(dp[i-1][1],dp[i-1][2]))+1;
        if(x == 1||x == 3)
            dp[i][1] = min(dp[i-1][0],dp[i-1][2]);
        if(x == 2||x == 3)
            dp[i][2] = min(dp[i-1][0],dp[i-1][1]);
    }
    printf("%d\n",min(dp[n][0],min(dp[n][1],dp[n][2])));
    return 0;
}

 



 

posted on 2016-08-18 21:52  polarday  阅读(137)  评论(0编辑  收藏  举报

导航