public class Solution_qingwatiao
{
public int RectCover(int target)
{
int result[] =
{ 0, 1, 2 };
if (target <= 2)
{
return result[target];
}
int f0 = 1;
int f1 = 2;
int f2 = 0;
for (int i = 3; i <= target; i++)
{
f2 = f1 + f0;
f0 = f1;
f1 = f2;
}
return f2;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int target = sc.nextInt();
Solution_qingwatiao cover = new Solution_qingwatiao();
System.out.println(cover.RectCover(target));
}
}
java实现一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
最新推荐文章于 2021-10-27 15:03:09 发布