public static void findTheNum(Integer[] array,List<Integer> res,int currentIndex, int averageScore) { if(isDone()){ output(res); return; } int j; for(int i =currentIndex;i<array.length;i++){ for(j=i+1;j<array.length;j++){ if((array[i] + array[j]) % averageScore == 0 && flag[j] != 1 && flag[i] != 1){ res.add(array[i]); res.add(array[j]); flag[j] = 1; flag[i] = 1; findTheNum(array, res, i + 1, averageScore); flag[j] = 0; flag[i] = 0; res.remove(array[i]); res.remove(array[j]); } } } } 没有用例,好像正常dfs,bfs都行