当前位置:网站首页>递归递推之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,再仔细回想就会发现错误。
代码:
边栏推荐
- CodeForces - 834C
- 生成树协议STP(Spanning Tree Protocol)
- 中科院深圳先进技术院合成所赵国屏院士组2022年招聘启事
- The basic components of Loudi plant cell laboratory construction
- 漏洞管理计划的未来趋势
- 娄底疾控中心实验室设计理念说明
- 关于flask中static_folder 和 static_url_path参数理解
- 娄底干细胞制备实验室建设须知要求
- 一个 CRM One Order Application log 的单元测试报表
- Merge similar items in LeetCode simple questions
猜你喜欢

DNS欺骗-教程详解

想通这点,治好 AI 打工人的精神内耗

LeetCode中等题之搜索二维矩阵

Keithley DMM7510精准测量超低功耗设备各种运作模式功耗

Efficient and Robust 2D-to-BEV Representation Learning via Geometry-guided Kernel Transformer Paper Notes

AICOCO AI Frontier Promotion (8.10)

Jenkins修改端口号, jenkins容器修改默认端口号

LeetCode·每日一题·640.求解方程·模拟构造

LeetCode中等题之颠倒字符串中的单词

Comparison version number of middle questions in LeetCode
随机推荐
mSystems | Zhongnong Wang Jie Group Reveals the Mechanisms Affecting Soil "Plastic Interstitial" Microbial Communities
CV复习:空洞卷积
odps sql 不支持 unsupported feature CREATE TEMPORARY
MySQL面试题——MySQL常见查询
表中存在多个索引问题? - 聚集索引,回表,覆盖索引
「网络架构」网络代理第一部分: 代理概述
rpn:def concat_box_prediction_layers
山水的高度
Ethernet channel 以太信道
Comparison version number of middle questions in LeetCode
Nanodlp v2.2/v3.0光固化电路板,机械开关/光电开关/接近开关的接法和系统状态电平设置
Inventory of Loudi Agricultural Products Inspection Laboratory Construction Guidelines
phpstrom 快速注释:
[List merge] Combine multiple lists into one list
Wirshark common operations and tcp three-way handshake process example analysis
【iOS】面试整理
Custom filters and interceptors implement ThreadLocal thread closure
Open Office XML 格式里如何描述多段具有不同字体设置的段落
娄底干细胞制备实验室建设须知要求
LeetCode中等题之比较版本号