编译失败??
查看原帖
编译失败??
638272
thehanged楼主2024/3/11 18:27

不知道为什么编译失败。 我测试了gcc和msvc都能编译成功,这就奇怪了

#include <iostream>
using namespace std;

const int N = 12;

int n, k;
int solution[N]; // 储存解决方案
bool st[N]; // 标志当前位置有没有被使用过

dfs(int x){
    if(x == k){ // 枚举到最后一位
        for(int i = 0; i < k; ++i) {
            cout << solution[i] << " ";
        }
        puts("");
    }
    for(int i = 1; i <= n; ++i){ // 枚举n名学生 
        if(!st[i]){
            solution[x] = i;
            // 往下枚举
            st[i] = true;
            dfs(x + 1);
            // 恢复现场
            st[i] = false;
            
        }
    }
}

int main(){
    cin >> n >> k;
    dfs(0);
    return 0;
}
2024/3/11 18:27
加载中...