当前位置:网站首页>递归递推之Fighting_小银考呀考不过四级
递归递推之Fighting_小银考呀考不过四级
2022-08-10 12:36:00 【51CTO】
题目大概:
一行有n个座位,每两个人之间至少空两个座位,求至少一个人的情况下的作为的做法。
思路:
a[n]为n个座位有的所有做法。假设前面的作为已经排好,第n个座位有两种情况,有人做和没人做,当有人做时,n-1和n-2一定没人做,所以和坐法和a[n-3]的数量时一样的,当没人坐时,那就和a[n-1]上的坐法是一样的,但还有一种情况,即当只有一个人坐时,a[n]上坐一人也算一种情况,故得出公式a[n]=a[n-1]+a[n-3]+1。
感想:
这个题有些难想,但不难想到要用公式能递推出所有的坐法,并且一般后面的数据于前面的有联系,但最后的加一容易忘掉,但调试的时候会发现每个数都会小1,再仔细回想就会发现错误。
代码:
边栏推荐
- 海外邮件发送指南(二)
- DNS欺骗-教程详解
- Overview of Loudi Petrochemical Experiment Design and Construction Planning
- 「网络架构」网络代理第一部分: 代理概述
- Merge similar items in LeetCode simple questions
- OTA自动化测试解决方案---整体方案介绍
- ASP.NET Core依赖注入系统学习教程:ServiceDescriptor(服务注册描述类型)
- 交换机的基础知识
- Blast!ByteDance successfully landed, only because the interview questions of LeetCode algorithm were exhausted
- Codeforces Round #276 (Div. 1) B. Maximum Value
猜你喜欢

表中存在多个索引问题? - 聚集索引,回表,覆盖索引

es6-promise对象详解

Is there a problem with the CURRENT_TIMESTAMP(6) function?

How to cultivate the design thinking of ui designers?

wirshark 常用操作及 tcp 三次握手过程实例分析
What are the five common data types of Redis?What is the corresponding data storage space?Take you to learn from scratch

shell:正则表达式及三剑客grep命令

漏洞管理计划的未来趋势

Nanodlp v2.2/v3.0 light curing circuit board, connection method of mechanical switch/photoelectric switch/proximity switch and system state level setting

Chapter9 : De Novo Molecular Design with Chemical Language Models
随机推荐
娄底妆品实验室建设规划构思
百度用户产品流批一体的实时数仓实践
漏洞管理计划的未来趋势
广东10个项目入选工信部2021年物联网示范项目名单
rpn:def concat_box_prediction_layers
Deploy the project halfway through the follow-up
跨域的五种解决方案
在web页面播放rtsp流视频(webrtc)
LeetCode medium topic search of two-dimensional matrix
Digicert EV证书签名后出现“证书对于请求用法无效”的解决方案
Keithley DMM7510 accurate measurement of ultra-low power consumption equipment all kinds of operation mode power consumption
CV复习:空洞卷积
bgp双平面实验 路由策略控制流量
Inventory of Loudi Agricultural Products Inspection Laboratory Construction Guidelines
H264 码率控制
娄底污水处理厂实验室建设管理
表中存在多个索引问题? - 聚集索引,回表,覆盖索引
Loudi Sewage Treatment Plant Laboratory Construction Management
How to do foreign media publicity to grasp the key points
什么是云流化?