2013年(92)
分类: 信息化
2013-02-25 02:31:03
[代码] [Java]代码 package test; ? public class Stairs { ? ????/** ?????* @author Cxl ?????* @version 2013-1-8 下午2:44:43 ?????* @Contract ?????* @param args ?????*/ ????public ; static void main(String[] args) { ????????int n = 5; ????????int maxStep = 3; ????????System.out.println("计划数:" getStepNum(n, maxStep)); ????} ????/** ?????* ?????* @author Cxl ?????* @version 2013-1-8 下午2:29:31 ?????* @Contract ?????* @param n 总的台阶数 ?????* @param m 一次能够走的最大楼梯阶数 ?????* @return ?????*/ ????private static int getStepNum(int n, int m) { ????????int sumStep = 0; ????????//总台阶数为0时,停止递归循环 ????????if (n == 0) { ????????????return 1; ????????} ????????if (n >= m) { ????????????//若是n大于每步最大台阶数,则设置第一步为m之内的一个台阶数,然后递归循环 ????????????for (int i = 1; i <= m; i ) { ????????????????sumStep = getStepNum(n - i, m); ????????????} ????????} ????????//若是n小于m,则将一步最大台阶数减少为n,从头递归 ????????else { ????????????sumStep = getStepNum(n, n); ????????} ????????return sumStep; ????} } ;