• 【dp】10-8题解 vacation


    vacations


    原题codeforeces round 363 (Div2) c

    题目描述

    暑假到了, Pb 正在计划他的假期。 Pb 准备假期去体育馆锻炼或看电影。但体育馆和电影院都有可能当天不开放。
    因此每一天有 4 中状态,我们用 0,1,2,3 表示。
    0:体育馆和电影院都关闭。
    1:体育馆关闭,电影院开放。
    2:体育馆开放,电影院关闭。
    3:体育馆和电影院都开放。
    Pb 不希望一天没有任何事情可做也不希望连续两天做同一件事,
    现在请你为 Pb 安排假期计划,在满足没有连续两天做同一件事的前提下最小化 Pb 无事可做的天数。

    输入描述

    第一行有一个数 N 表示 Pb 的假期天数。 接下来 N 个整数表示假期每一天的状态。(用 0,1,2,3 表示,意义见题目描述)

    输出描述

    输出一个整数表示满足条件的 Pb 无事可做天数的最小值。
    样例输入

    4 1 3 2 0
    

    样例输出

    2
    

    数据范围及提示

    对于 30%的数据, 0<n<=15>
    对于 60%的数据, 0<n<=1000>
    对于 100%的数据, 0<n<=1000000

    代码

    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    #include<string>
    #include<ctype.h>
    #include<math.h>
    #include<set>
    #include<map>
    #include<vector>
    #include<queue>
    #include<bitset>
    #include<algorithm>
    #include<time.h>
    #define MS(x,y) memset(x,y,sizeof(x))
    #define MC(x,y) memcpy(x,y,sizeof(x))
    #define MP(x,y) make_pair(x,y)
    #define ls o<<1
    #define rs o<<1|1
    using namespace std;
    typedef long long LL;
    typedef unsigned long long UL;
    typedef unsigned int UI;
    template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
    template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
    const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
    int n;
    int f[105][3];
    int main()
    {
        while (~scanf("%d", &n))
        {
            MS(f, 63); f[0][0] = 0;
            for (int i = 1; i <= n; ++i)
            {
                int x; scanf("%d", &x);
                if (x == 1 || x == 3)//可以参加考试
                {
                    f[i][1] = min(f[i - 1][0], f[i - 1][2]);
                }
                if (x == 2 || x == 3)//可以参加运动
                {
                    f[i][2] = min(f[i - 1][0], f[i - 1][1]);
                }
                //休息
                f[i][0] = min(f[i - 1][0], min(f[i - 1][1], f[i - 1][2])) + 1;
            }
            int ans = 1e9;
            gmin(ans, f[n][0]);
            gmin(ans, f[n][1]);
            gmin(ans, f[n][2]);
            printf("%d
    ", ans);
        }
        return 0;
    }
    

      

     
  • 相关阅读:
    Nginx得知——Hello World模
    Web静态和动态项目委托代理基于面向方面编程AOP
    PIC16SCM设置不同IO功耗端口状态的影响
    $.ajax通路RESTful Web Service一个错误:Unsupported Media Type
    什么是Entitlement
    加解密
    Types of Security Vulnerabilities
    fork后子进程从哪里开始执行
    进程间通信(IPC)介绍
    Using URL Schemes to Communicate with Apps
  • 原文地址:https://www.cnblogs.com/bbqub/p/7668856.html
Copyright © 2020-2023  润新知