求助
查看原帖
求助
1569976
SpeedNoclippers楼主2025/1/22 12:06
#include<bits/stdc++.h>
using namespace std;
int a[25];

void dfs(int pos,int st,int r,int n)
{
    if(pos==r)
    {
        for(int i=1;i<=r;i++) cout << setw(3) << a[i];
        cout<<endl;
        return;
    }
    for(int i=st;i<=n;i++)
    {
        a[pos]=i;
        dfs(pos+1,i+1,r,n);
    }
}

int main()
{
    int n,r;cin>>n>>r;
    if(r==0)return 0;
    dfs(0,1,r,n);
    return 0;
}

只对了最后一个,求助

2025/1/22 12:06
加载中...