第七个too short 但是输出好像没问题..不知道哪里错了,求指教
查看原帖
第七个too short 但是输出好像没问题..不知道哪里错了,求指教
300317
xiaoxiaobaibai楼主2021/1/24 22:04

#include<bits/stdc++.h>
using namespace std;
int n,r;
int result[22];
int used[22];
void print()
{
    int i;
    for(i=0;i<r;i++)
    {
        cout<<setw(3)<<result[i];
    }
    cout<<endl;
}

void dfs(int location)
{
    int i;
    if(location==r)
    {
        print();
        return ;
    }
    else
    {
        for(i=0;i<n;i++)
        {
            if(location==0&&i>=r)
            {
                break;
            }
            if(location==0&&used[i]==0||used[i]==0&&i+1>result[location-1])
            {
                used[i]=1;
                result[location]=i+1;
                dfs(location+1);
                used[i]=0;
            }
        }
    }
    
}
int main()
{
    cin>>n>>r;
    dfs(0);
    return 0;
}
2021/1/24 22:04
加载中...