热门

最新

红包

立Flag

投票

同城

我的

发布
likeaclle
likeaclle
3 年前
truelikeaclle

public class RoomEscapeGame {

public static int countRoutes(int current, int target, int toxic1, int toxic2) {
// 边界条件
if (current == target) {
return 1;
}
if (current == toxic1 || current == toxic2) {
return 0;
}

// 递归计算路线方案数
return countRoutes(current + 1, target, toxic1, toxic2) + countRoutes(current + 2, target, toxic1, toxic2);
}

public static void main(String[] args) {
int X = 2; // 第一个有毒气的密室编号
int Y = 3; // 第二个有毒气的密室编号
int M = 100; // 目标密室编号

int routeCount = countRoutes(1, M, X, Y);
System.out.println("路线方案数:" + routeCount);
}
}

@m0_75263691:这个用Java有大神会做吗

…全文
CSDN App 扫码分享
分享
1
1
打赏
  • 复制链接
  • 举报
下一条:
立即登录