当前位置:网站首页>【暑期每日一题】洛谷 P1255 数楼梯
【暑期每日一题】洛谷 P1255 数楼梯
2022-08-02 06:07:00 【AC_Dragon】
题目链接:P1255 数楼梯 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
题目描述
楼梯有 N 阶,上楼可以一步上一阶,也可以一步上二阶。
编一个程序,计算共有多少种不同的走法。
输入格式
一个数字,楼梯数。
输出格式
输出走的方式总数。
样例 #1
样例输入 #1
4样例输出 #1
5提示
- 对于 60% 的数据,N <= 50;
- 对于 100% 的数据,1 <= N <= 5000。
AC code:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
string f(string a,string b)
{
if(a=="0" && b=="0")
{
return "0";
}
int t1=a.size();
int t2=b.size();
int n=abs(t1-t2);
for(int i=0;i<n;i++)
{
if(t1>t2)
b="0"+b;
else
a="0"+a;
}
string s; // 和
int c=0; // 进位
int d=0; // 低位
int len=a.size()-1;
for(int i=len;i>=0;i--)
{
d=(a[i]-'0'+b[i]-'0')%10+c;
if(d==10)
{
c=1;
s="0"+s;
continue;
}
s=to_string(d)+s;
c=(a[i]-'0'+b[i]-'0')/10;
if(c==1 && i==0)
s="1"+s;
}
if(s[0]=='0')
s="1"+s;
return s;
}
int main()
{
vector<string> a(1);
a.push_back("1");
a.push_back("2");
for(int i=3;i<=5000;i++)
{
string t=f(a[i-2],a[i-1]);
a.push_back(t);
}
int n;
cin>>n;
cout<<a[n];
return 0;
}边栏推荐
- .NET静态代码织入——肉夹馍(Rougamo) 发布1.1.0
- [Dataset][VOC] Male and female dataset voc format 6188 sheets
- MySQL Advanced Study Notes
- Difference between npm and yarn
- Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
- [数据集][VOC]眼睛佩戴数据集VOC格式6000张
- At age 94, pioneer Turing award winner, computational complexity theory, Juris Hartmanis, died
- 笔记本开机黑屏提示:ERROR 0199:System Security-Security password retry count exceeded
- 有人开源全凭“为爱发电”,有人却用开源“搞到了钱”
- Node installation and environment configuration
猜你喜欢

Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing

MySQL 5.7 安装教程(全步骤、保姆级教程)

How the Internet of Things is changing the efficiency of city operations

SphereEx苗立尧:云原生架构下的Database Mesh研发实践

mysql高阶语句(一)

Xgboost报错 ValueError: Invalid shape: (1650, 2) for label

Nodejs installation tutorial

Technology empowers Lhasa's "lungs", Huawei helps Lalu Wetland Smart Management to protect lucid waters and lush mountains

APT + Transform to realize multi module Application distributed Application life cycle

(笔记整理未完成)【图论】图的遍历
随机推荐
HCIP 第三天实验
[Dataset][VOC] Male and female dataset voc format 6188 sheets
How does abaqus quickly import the assembly of other cae files?
(部分不懂,笔记整理未完成)【图论】差分约束
Mining game (C language)
武汉高性能计算大会2022举办,高性能计算生态发展再添新动力
打卡day05
C# FileInfo class
有点奇怪!访问目的网址,主机能容器却不行
The nacos source code can not find the istio package
解决C#非静态字段、方法或属性“islandnum.Program.getIslandCount(int[][], int, int)”要求对象引用
数据库概论之MySQL表的增删改查2
pointer arithmetic in c language
APT + Transform to realize multi module Application distributed Application life cycle
Detailed explanation of 9 common reasons for MySQL index failure
2022年7月18日-7月31日(Ue4视频教程和文档,20小时。合计1412小时,剩8588小时)
Nacos installation configuration and single-machine deployment tutorial
MySQL高阶---存储引擎、索引、锁
【21天学习挑战赛】顺序查找
Dataset:机器学习中常用数据集下载链接集合之详细攻略