当前位置:网站首页>洛谷P2437蜜蜂路线
洛谷P2437蜜蜂路线
2022-08-02 04:03:00 【zjsru_Beginner】
题目描述
一只蜜蜂在下图所示的数字蜂房上爬动,已知它只能从标号小的蜂房爬到标号大的相邻蜂房,现在问你:蜜蜂从蜂房 m 开始爬到蜂房 n,m<n,有多少种爬行路线?(备注:题面有误,右上角应为 n-1)
输入格式
输入 m,n 的值
输出格式
爬行有多少种路线
输入输出样例
输入 #1复制
1 14
输出 #1复制
377
说明/提示
对于100%的数据,1≤M,N≤1000
解题思路:
从题目中,我们不难发现问题的解类似斐波那契数列,也就是f[i]=f[i-1]+f[i-2]。到这里我们就完成了第一步。第二步,由于本题的数据较大,超过范围,所以我们还要进行高精度加法处理。
代码如下:
#include <iostream>
using namespace std;
int m, n,len=1;
int c[1005][1005];
void compute(int index) {
int i=1,x=0;
while (i <= len) {
c[index][i] = c[index-1][i] + c[index-2][i] + x;
x = c[index][i] / 10;
c[index][i] %= 10;
i++;
}
if (x != 0) {
c[index][len + 1] = x;
len++;
}
}
int main() {
cin >> m >> n;
c[m + 1][1] = 1;
c[m + 2][1] = 2;
for (int i = m + 3; i <= n; i++) {
compute(i);
}
for (int i = len; i >= 1; i--) {
cout << c[n][i];
}
return 0;
}
边栏推荐
猜你喜欢
Jetson Nano 2GB Developer Kit Installation Instructions
科研笔记(七) 基于路径规划和WiFi指纹定位的多目的地室内导航
redis基础入门
如何评价最近爆红的FastAPI?
Excel skills daquan
互动投影墙深受展览展示喜爱的原因分析
科研笔记(六) 基于环境感知的室内路径规划方法
三维目标检测之OpenPCDet环境配置及demo测试
Research Notes (8) Deep Learning and Its Application in WiFi Human Perception (Part 2)
批量--10---根据set数拆分文件
随机推荐
列表总结
(一)代码输出题 —— reverse
使用 Fastai 构建食物图像分类器
[Study Notes] How to Create an Operation and Maintenance Organizational Structure
自定义一个下划线分词器
Pycharm platform import scikit-learn
Andrew Ng's Machine Learning Series Course Notes - Chapter 18: Application Example: Image Text Recognition (Application Example: Photo OCR)
Nexus 5手机使用Nexmon工具获取CSI信息
The CCF brush topic tour - the first topic
jetracer_pro_2GB AI Kit system installation instructions
Go 语言是如何实现切片扩容的?【slice】
多主复制的适用场景(2)-需离线操作的客户端和协作编辑
[Win11] PowerShell无法激活Conda虚拟环境
Jetson Nano 2GB Developer Kit Installation Instructions
Computer Basics
如何解决QByteArray添加quint16双字节时错误?
【C语言程序】求直角三角形边长
温暖的世界
张成分析(spanning test):portfolio_analysis.Spanning_test
MySQL读写分离mysql-proxy部署