当前位置:网站首页>1230: 蜂巢
1230: 蜂巢
2022-08-03 05:10:00 【-JMY-】
题目描述
一只蜜蜂在下图所示的数字蜂房上爬动,已知它只能从标号小的蜂房爬到标号大的相邻蜂房,现在问你:蜜蜂从蜂房M开始爬到蜂房N,M<N,有多少种爬行路线?
输入
只有一行,是2个用空格隔开的整数M,N(1<=M,N<=60)。
输出
只有1行,1个整数,即有多少种爬行路线。
样例输入
1 3
样例输出
2
(这题其实是找规律,明白规律就很简单了)
参考代码:
#include<bits/stdc++.h>
using namespace std;
long long a[2][60],m,n,l;
int main(){
cin>>m>>n;
a[0][0]=1;
a[1][0]=1;
while(m>1){
m--;
n--;
}
for(l=1;l<=(n-1)/2;l++){
a[0][l]=a[0][l-1]+a[1][l-1];
a[1][l]=a[0][l]+a[1][l-1];
}
cout<<a[1-n%2][l-1];
return 0;
}
边栏推荐
猜你喜欢
随机推荐
曲线特征----曲线弯曲程度的探究
设计模式——组合模式、享元模式(Integer缓存)(结构型模式)
High availability, two locations and three centers
Super handy drawing tool is recommended
minio下载文件乱码或者是一条横线
2. 两数相加
Flink state
Apache DolphinScheduler版本2.0.5分布式集群的安装
深度学习入门之GRU
odps的临时查询能在写sql的时候就给结果一个命名不?
3. 无重复字符的最长子串
Exception(异常) 和 Error(错误)区别解析
Install PostgreSQL on Windows
The problem that the rosbag tool plotjuggler cannot open rosbag
HarmonyOS应用开发培训第二次作业
13.< tag-动态规划和回文字串>lt.647. 回文子串 + lt.516.最长回文子序列
Detailed explanation of MOSN reverse channel
ss-1.curl (cloud-provider-payment8001)
Install IIS services (Internet Information Services (Internet Information Services, abbreviated IIS, Internet Information Services)
MCM box model modeling method and source analysis of atmospheric O3