Vacations (DP)

Cesium中实现阴影率分析 看到群里有人在研究这个,所以看了一下。主要是模仿超图的,实现原理超图有做回答:但其实超图的这个实现方式还是过于复杂,原因是:既然是获取太阳的日照阴影,而Cesium中原本就存在太阳,且能投射阴影,因此其实并不需要再次计算太阳位置并计算视锥获取深度图,直接使用Cesium原生的太阳深度图即可。 阅读详情

Vacations

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:

  1. on this day the gym is closed and the contest is not carried out;
  2. on this day the gym is closed and the contest is carried out;
  3. on this day the gym is open and the contest is not carried out;
  4. 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:

  • to do sport on any two consecutive days,
  • to write the contest on any two consecutive days.
Examples
Input
4
1 3 2 0
Output
2
Input
7
1 3 3 2 1 2 3
Output
0
Input
2
2 2
Output
1
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.

题意:Vasya在n天中,有三件事情可以做,健身、写作或者休息,但是健身和写作不能连续两天都去做,但是连续休息两天是允许的,问题是在这n天中,Vasya最少可以休息几天?
题解:动态规划初级题目吧,dp[第几天][昨天干了什么] = 从第1天到第i天最少休息天数。
状态转移方程:

dp[i][0] = min(min(dp[i-1][1],dp[i-1][2]),dp[i-1][0]) + 1;

再根据所给的数字,确定当前做某个活动时的最小休息天数

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int INF = 0x3f3f3f3f;
int main(){
    int n;
    int dp[120][3];
    scanf("%d",&n);
    memset(dp,INF,sizeof(dp));
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++){
        int m;
        scanf("%d",&m);
        dp[i][0] = min(min(dp[i-1][1],dp[i-1][2]),dp[i-1][0]) + 1;   //如果今天休息
        if(m == 1){
            dp[i][1] = min(dp[i-1][0],dp[i-1][2]);
        }
        else if(m == 2){
            dp[i][2] = min(dp[i-1][0],dp[i-1][1]);
        }
        else if(m == 3){
            dp[i][1] = min(dp[i-1][0],dp[i-1][2]);
            dp[i][2] = min(dp[i-1][0],dp[i-1][1]);
        }
    }
    printf("%d\n",min(min(dp[n][1],dp[n][2]),dp[n][0]));
    return 0;
}

[Dify实战] 做企业内部助手时,最容易被低估的不是提示词,而是权限、状态同步和反馈回写 这篇文章围绕“做企业内部助手时”这个具体问题展开,很多团队做企业内部助手时,最先优化的是提示词,但真正决定系统能不能上线长期跑下去的,往往是权限边界、状态同步和反馈回写闭环。正文会结合Dify拆解节点设计、配置建议和测试样例,补充关键步骤、检查点和常见坑,帮助读者判断第一版该怎么落地,并把经验复用到自己的真实业务场景中。 阅读详情

相关推荐

从Canny到深度学习:边缘检测指标进化史(含ODS/OIS/AP的数学推导)

本文系统梳理了边缘检测评估指标的演进历程,从经典的Canny算子到深度学习时代,重点解析了ODS、OIS和AP三大核心指标的设计哲学与数学推导。文章深入探讨了基于PR曲线的评估体系,揭示了不同指标(如ODS与OIS)在阈值优化上的差异,并分析了AP指标在边缘检测任务中的优势与局限,为算法研究和模型评估提供了实用指南。

b9c0d的博客 202

Codeforces 699 C. Vacations ( 贪心

C. Vacationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasy

Yishui_lovely 376

新能源车主必看:用高德API+充电站数据制作跨城出行充电规划工具(附完整代码)

本文为新能源车主提供了一份详细的跨城出行充电规划工具构建指南。通过整合高德地图API与充电站数据,手把手教你使用Python开发一个智能规划系统,可自动规划路线并推荐沿途充电站,有效缓解里程焦虑。文章包含完整代码、核心算法解析及可视化实现,帮助车主实现个性化、高效的出行规划。

tgb3456789的博客 909

Vacation题解及其延申---线性dp

上一瓶插哪朵花,这样我们可以顺着pre数组逆推回去,同时还要注意的一点在于再遍历第j种花时由于当前一个花与花瓶的序号小于等于后一个花与花瓶的序号,即说明在遍历时后一个状态只能在区间。表示前i天且第i天进行第j个活动的最大值,由于连续两天不相同,我们可以枚举今天与前一天进行了哪些活动进行状态转移,最后记录这些状态的最大值,时间复杂度。这里我简要只讲我的思路,详情可以做一做,这题目首先我们可以发现这题的状态转移方程并没有发生改变,进行(要留下足够的花瓶),遍历一边即可,时间复杂度。

2401_82728478的博客 582

dify智能体:日志管理与标注功能详解

日志管理与标注功能是优化聊天助手、Agent、文本生成应用、Chatflow 和工作流等工具交互体验的关键。日志管理允许用户查看、修改和标注日志,帮助回顾和优化交互内容。用户可以通过点击👍或👎按钮快速标注满意度,标注后的日志可用于后续优化和分析。标注功能则支持用户对交互内容进行标记和调整,以提升模型输出质量。此外,用户还可以调整界面语言和时区设置,确保在熟悉的环境中操作。这些功能共同作用,显著提升了交互体验和模型性能。

zyx_bx的博客 2718

安装m_map以及用matlab绘制高精度海岸线地图

#如何用matlab绘制高精度海岸线地图

qq_38512775的博客 1万+

2016 北邮暑期训练3-D题(Codeforces 698A Vacations)DP,水题

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 c

1202

Oracle 11g版本下载及安装超详细教程图解

新手Oracle安装教程

weixin_43738344的博客 10万+

UVA 10192 Vacation(dp + LCS)

Problem E: Vacation  The Problem You are planning to take some rest and to go out on vacation, but you really don't know which cities you should visit. So, you ask your parents for hel

Remilia's 1089

手把手教你用ROS2控制PX4无人机画个圆:从C++代码到Gazebo仿真全流程解析

本文详细解析了如何使用ROS2控制PX4无人机实现圆形轨迹飞行,涵盖从C++代码编写到Gazebo仿真的全流程。重点介绍了Offboard模式下的控制算法实现、圆形轨迹生成的数学原理,以及解决通信延迟和坐标系转换等常见问题的实用技巧。通过实战案例,帮助开发者快速掌握无人机轨迹跟踪仿真的核心技术。

weixin_30839881的博客 101

Istio ICA考试之路---2-2

找到dr部分,这部分可以在mirroring里找也可以和题2-1一样在Traffic Management的dr里复制,内容都一样。此题之后都是在cluster-2上操作,所以就不需要再切换了.之后的几题2.1节就忽略掉了。可以看到,80%的流量被镜像到了dev上,实际考试这步可以忽略。看到ex-ip是192.168.126.220。获取gw,把gateways加入到vs配置中。获取istio-ingress的ex-ip。就获得了这样一个模板文件。查看2个pod的日志。

Q先生 858

CF698A. Vacations【DP】

题目链接http://codeforces.com/problemset/problem/698/A思路设dp[i][j]表示在第i天干第j种事情,前i天的最小休息天数。 j=0表示休息,1打代码,2运动。不可能的状态置为INF,转移方程就很简单了,具体见代码。 比赛时愣是没想到用dp,早上瞄一眼题解才发现这么简单,总归还是太弱了。AC代码#include <iostream> #include

初涉_代码世界 1044

【26美赛C题】Data With The Stars第三问[影响因素分析模型]思路与代码

本文针对2026美赛C题《Dancing with the Stars》第二问,提出了一套系统的影响因素分析框架。通过多元回归模型和固定效应模型,量化分析了明星特征(年龄、职业等)、舞者搭档和比赛周次对评分的影响,发现评委与观众偏好存在差异。研究采用方差分解评估舞者效应占比,通过最优年龄分析和交互效应检验揭示非线性关系。最后运用差异性检验和结构方程模型(SEM)比较评委与观众偏好,为比赛结果预测和选手优化提供量化依据。该分析框架可系统揭示比赛成绩的关键驱动因素。

一键难忘的博客 762

Vacations【Codeforces 699 C】【dp】

Codeforces Round #363 (Div. 2) C 有四种状态: gym不开,contest不开; gym不开,contest开; gym开,contest不开; gym开,contest开; 然后我们可以选择休息一天,也可以选择打,但是如果昨天做了gym今天是不能做gym的,同理,昨天做了contest,今天也是不能打contest的。现在问的就是最少休息的天数是几...

既然弱小,就只顾变强就是了 260

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

A. Vacations (dp 贪心

添加链接描述 dp方程是选择健身 选择工作 选择比赛的最少休息天数

我见青山多妩媚,料青山见我应如是 340

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

codeforces 698A Vacations 基础dp

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 ca

黑码 425

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Vacations dp动态规划题目

dp动态规划题目

m0_73622521的博客 1084

Vacations(DP)

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

码农的一亩三分地 397

Vacations(dp)

题目链接: Vacations 大致题意: 有三种状态:0表示休息,1表示学习,2表示运动,三表示学习运动二选一 给出n种状态,问最少可以休息几天(连续两天不能做同一件事) 解题思路: dp[i][j]来表示第i天做j事的最小休息天数 AC代码: #include <bits/stdc++.h> using namespace std; const int N = 200, INF = 0x3f3f; int n; int a[N]; int f[N][4]; int main() {

qq_49494204的博客 236

CodeForces - 698A Vacations 贪心 dp

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

liluoyu_1016的博客 409

Codeforces 698A Vacations DP

Codeforces 698A Vacations DP CF

阑珊记忆 414

CodeForces - 698A ——Vacations(dp)

Vasya hasndays of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of thisndays: whether that gym opened and whether a contest was c...

red_red_red的博客 173

[CF699C]Vacations(DP)

题目链接:http://codeforces.com/contest/699/problem/C 实验室网络最近炸了,看个题面都费半天劲,题解就写的少了。晚上回宿舍水一发DP。 一个人在一段时间内想做打比赛或者去运动,但是每一天有两种情况:运动场是否开门或者有无比赛。题目用0~3来代表这两个事情。这个人想在这段时间内休息得最少(每天都有事做),但是相邻两天不能做同样的事情,问他最少休息多少天。...

weixin_30699955的博客 179

CFA. Vacations题解,一维DP

DP

KJJD7的博客 163

Codeforces 698A Vacations(线性DP)

题意: 每一天都有各种活动,也可以选择休息,问你如何安排才能够在前后两天惊醒的活动不一样的情况下,是的休息的天数最少。 分析: 直接暴力进行dp就可以了,注意前后活动不一样是的转移状态的不同。 // Created by CQU_CST_WuErli // Copyright (c) 2016 CQU_CST_WuErli. All rights reserved. // //#pra

只玩三国的程序猿的专栏 596

Codeforces 698A:Vacations(DP)

题目链接:http://codeforces.com/problemset/problem/698/A 题意 Vasya在n天中,有三件事情可以做,健身、比赛或者休息,但是不能连续两天都是比赛或都是但是健身,但是连续休息两天是允许的,问题是在这n天中,Vasya最少可以休息几天? 0代表休息,1代表比赛,2代表健身,3可以代表比赛也可以代表健身 思路 用数组dp[i][j]表示第i天...

执念 310
上一篇: Battleship (模拟)
下一篇: odd-even number (数位dp)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值