日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CodeForces 699C - Vacations

發(fā)布時(shí)間:2025/7/14 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CodeForces 699C - Vacations 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目鏈接:http://codeforces.com/problemset/problem/699/C


C. Vacations

time limit per test1 second
memory limit per test256 megabytes

Problem Description

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:

on this day the gym is closed and the contest is not carried out;
on this day the gym is closed and the contest is carried out;
on this day the gym is open and the contest is not carried out;
on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).

Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

Input

The first line contains a positive integer n (1?≤?n?≤?100) — the number of days of Vasya’s vacations.

The second line contains the sequence of integers a1,?a2,?…,?an (0?≤?ai?≤?3) separated by space, where:

  • ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
  • ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
  • ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
  • ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.
  • Output

    Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
    6. to do sport on any two consecutive days,
    7. to write the contest on any two consecutive days.

    Note

    In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.

    In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.

    In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.


    這是一個(gè)簡單的dp,然而完全沒想到,模擬也可以做。
    dp[i][j] (i:第幾天,j:昨天干了啥) = 從第1天到第n天最少休息了多少天。


    簡單模擬:

    #include<bits/stdc++.h> using namespace std; const int maxn = 110; int num[maxn]; bool z[maxn];//用于標(biāo)記前一天是否是休假 int main() {int n;while(scanf("%d",&n)!= EOF){memset(z,0,sizeof(z));for(int i=1;i<=n;i++)scanf("%d",&num[i]);int ans = 0;bool flag = false;bool flag2 = false;for(int i=1;i<=n;i++){int now = ans;if(num[i] == 0)ans++;else if(num[i] == 1){if(num[i-1] == 3 && num[i-2] == 2 && i-2 > 0 && !z[i-1] && !z[i-2])ans++;else if(num[i-1] == 1 && !z[i-1] && i-1 >0)ans++;}else if(num[i] == 2){if(num[i-1] == 3 && num[i-2] == 1 && i-2 > 0 && !z[i-1] && !z[i-2])ans++;else if(num[i-1] == 2 && !z[i-1] && i-1 > 0)ans++;}if(num[i] == 3 && num[i-1] == 1 && !z[i-1])num[i] = 2;else if(num[i] == 3 && num[i-1] == 2 && !z[i-1])num[i] = 1;if(ans > now)z[i] = true;}printf("%d\n",ans);}return 0; }

    用dp做:

    #include<bits/stdc++.h> using namespace std; const int maxn = 110; int dp[maxn][10]; int num[maxn]; int main() {int n;while(scanf("%d",&n) != EOF){memset(dp,0x7f,sizeof(dp));for(int i=0;i<=4;i++)dp[0][i] = 0;for(int i=1;i<=n;i++){int temp;scanf("%d",&temp);dp[i][0] = min(dp[i-1][1],min(dp[i-1][2],dp[i-1][0])) + 1;//前一天是休假,今天的dp++;if(temp == 1)dp[i][2] = min(dp[i-1][0],dp[i-1][1]);//今天做1,昨天做2或者休假if(temp == 2)dp[i][1] = min(dp[i-1][0],dp[i-1][2]);//今天做2,昨天做1或者休假if(temp == 3){dp[i][2] = min(dp[i-1][0],dp[i-1][1]);dp[i][1] = min(dp[i-1][0],dp[i-1][2]);}}printf("%d\n",min(dp[n][1],min(dp[n][2],dp[n][0])));}return 0; }

    轉(zhuǎn)載于:https://www.cnblogs.com/GoldenFingers/p/9107249.html

    總結(jié)

    以上是生活随笔為你收集整理的CodeForces 699C - Vacations的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。