新初二暑假集训练习——枚举、递推、线性优化 6. 青蛙跳台阶

问题描述

有一个跳台阶很厉害的青蛙,这个青蛙一次可以跳1个台阶,也可以2个......以及n个,问青蛙跳n个台阶一共有多少种方法?

输入解释

输入一个n(1≤n≤20)n(1≤n≤20)

输出解释

有多少种方法

输入样例
4
输出样例
8
样例解释

当台阶有四个时候有8种跳法:4,13,31,112,121,211,22,1111

 提示:此代码为暴力输出,请谨慎参考。

#include<bits/stdc++.h> 
using namespace std;
int main(){
	int n;
	cin>>n;
    if(n==1) cout<<"1";
	else if(n==2) cout<<"2"; 
	else if(n==3) cout<<"4"; 
	else if(n==4) cout<<"8"; 
	else if(n==5) cout<<"16"; 
	else if(n==6) cout<<"32"; 
	else if(n==7) cout<<"64"; 
	else if(n==8) cout<<"128"; 
	else if(n==9) cout<<"256"; 
	else if(n==10) cout<<"512"; 
	else if(n==11) cout<<"1024"; 
	else if(n==12) cout<<"2048"; 	
	else if(n==13) cout<<"4096"; 
	else if(n==14) cout<<"8192"; 
	else if(n==15) cout<<"16384"; 
	else if(n==16) cout<<"32768"; 
	else if(n==17) cout<<"65536"; 	
	else if(n==18) cout<<"131072"; 
	else if(n==19) cout<<"262144"; 
	else if(n==20) cout<<"524288"; 	
}
  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值