当前位置:网站首页>Dynamic planning daily practice (1)
Dynamic planning daily practice (1)
2022-07-23 13:30:00 【Dragon roar @ ~】
1. Fibonacci
class Solution {
public:
int fib(int n) {
if(n<=1)
{
return n;
}
else{
int q=0,p=0,s=1;
for(int i=2;i<=n;++i)
{
q=p;
p=s;
s=p+q;
}
return s;
}
}
};
The boundary condition of Fibonacci number is F(0)=0F(0)=0 and F(1)=1F(1)=1. When n>1n>1 when , The sum of each term is equal to the sum of the first two terms , Therefore, there is the following recurrence relationship :
F(n)=F(n-1)+F(n-2)
F(n)=F(n−1)+F(n−2)
2.T Teponacci sequence
T0 = 0, T1 = 1, T2 = 1, And in n >= 0 Under the condition of Tn+3 = Tn + Tn+1 + Tn+2
Give you an integer n, Please go back to n One tibonacci number Tn Value .
class Solution {
public:
int tribonacci(int n) {
if(n<=3)
{
if(n==0)
{
return 0;
}
else if(n<=2)
{
return 1;
}
else
{
return 2;
}
}
else{
int p=0,q=1,o=1,s=2;
for(int i=4;i<=n;i++)
{
p=q;
q=o;
o=s;
s=p+q+o;
}
return s;
}
}
};
边栏推荐
- Cortex-a series processor
- Jenkins持续集成报错stderr: fatal: unsafe repository (‘/home/water/water‘ is owned by someone else)
- 第七天筆記
- Bit synchronization process of CAN controller
- Opencv image processing (Part 1): geometric transformation + morphological operation
- JVM内存模型简介
- Notes on the seventh day
- Day 8 notes
- MySQL index transaction & JDBC programming
- Successful joint commissioning of Vientiane Aoke and CoDeSys Technology
猜你喜欢

Google Play应用商店可能会删除应用权限概述 转而使用新的数据安全信息组合

JVM detailed parsing

射击 第 1-3 课:图像精灵

PHP framework MVC class code audit

Beifu PLC and C transmit int type variables through ads communication

倍福PLC和C#通过ADS通信定时刷新IO

Are there any academic requirements for career transfer software testing? Is there really no way out below junior college?

php框架MVC类代码审计

Complex networks - common drawing software and libraries

倍福PLC和C#通过ADS通信传输String类型
随机推荐
[actf2020 freshman competition]backupfile 1
谈谈学习和工作——钱学森
【可視化調度軟件】上海道寧為SMB組織帶來NETRONIC下載、試用、教程
网易白帽子黑客训练营笔记(2)
C language - big end storage and small end storage
Paging collections using streams
Jupyter notebook add existing virtual environment
Why does the GOM engine version automatically drop the line or flash back?
国信证券软件开户是安全吗?信息会不会泄露?
北大博士小姐姐:分享压箱底干货 | 五招提高学习效率
太空射击 Part 2-3: 子弹与敌人碰撞处理
太空射击 Part 1: 玩家精灵和控制
第八天笔记
[ACTF2020 新生赛]BackupFile 1
倍福PLC和C#通过ADS通信传输String数组类型变量
Opencv image processing (medium) image smoothing + histogram
[jzof] 08 next node of binary tree
第十二天笔记
云解决方案,为什么选择 AMD EPYC?
High voltage MOS tube knx42150 1500v/3a is applied to frequency converter power supply inverter, etc