当前位置:网站首页>递归递推之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,再仔细回想就会发现错误。
代码:
边栏推荐
- Pod生命周期
- 2022 Recruitment Notice for Academician Zhao Guoping Group of Shenzhen Institute of Advanced Technology, Chinese Academy of Sciences
- 47Haproxy Cluster
- [Collection] HashSet and ArrayList lookup Contains() time complexity
- ArcMAP出现-15的问题无法访问[Provide your license server administrator with the following information:Err-15]
- 海外邮件发送指南(二)
- Reversing words in a string in LeetCode
- Have you guys encountered this problem?MySQL 2.2 and 2.3-SNAPSHOT are like this, it seems to be
- Jenkins修改默认主目录
- Overseas media publicity. What problems should domestic media pay attention to?
猜你喜欢
Nanodlp v2.2/v3.0光固化电路板,机械开关/光电开关/接近开关的接法和系统状态电平设置
Guo Jingjing's personal chess teaching, the good guy is a robot
2022年8月中国数据库排行榜:openGauss重夺榜眼,PolarDB反超人大金仓
神经网络可视化有3D版本了,美到沦陷!(已开源)
Digicert EV证书签名后出现“证书对于请求用法无效”的解决方案
【百度统计】用户行为分析
海外邮件发送指南(二)
关于flask中static_folder 和 static_url_path参数理解
Reversing words in a string in LeetCode
「企业架构」应用架构概述
随机推荐
MySQL索引的B+树到底有多高?
Codeforces Round #276 (Div. 1) B. Maximum Value
A detailed explanation of implementation api embed
Nanodlp v2.2/v3.0 light curing circuit board, connection method of mechanical switch/photoelectric switch/proximity switch and system state level setting
友邦人寿可观测体系设计与落地
Loudi Sewage Treatment Plant Laboratory Construction Management
Jenkins修改端口号, jenkins容器修改默认端口号
虚拟机桥接模式不能上网
MySQL面试题——MySQL常见查询
想通这点,治好 AI 打工人的精神内耗
Network Saboteur
Shell:数组
H264 GOP 扫盲
Keithley DMM7510 accurate measurement of ultra-low power consumption equipment all kinds of operation mode power consumption
I would like to ask the big guys, how to solve this error when cdc oracle initializes a 3 million table task running
The basic components of Loudi plant cell laboratory construction
Loudi Cosmetics Laboratory Construction Planning Concept
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama
线代 | 秒杀方法与技巧
Polygon zkEVM工具——PIL和CIRCOM