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); }}