0分RE
查看原帖
0分RE
1698714
Johnnyxu0715楼主2025/7/26 11:34
#include <bits/stdc++.h>
using namespace std;

const int N = 105;
int n, r;
int ans[N];
bool used[N];

int combine(int k)
{
	for(int i = ans[k-1]+1;i <= n;i++)
	{
		if(!used[i])
		{
			ans[k] = i;
			used[i] = 1;
			if(k == r)
			{
				for(int j = 1;j <= r;j++)
				{
					cout << setw(3) << ans[j];
				}
				cout << endl;
			}
			else
			{
				combine(k+1);
			}
			used[i] = 0;
		}
	}
}

int main()
{
	cin >> n >> r;
	combine(1);

	return 0;
}
2025/7/26 11:34
加载中...