记录程序(递归考试第一题

ykj12 2022-05-29 16:26:38 2022-05-29 16:28:34 0
#include <iostream>
#include <cstring>
#include <algorithm>
#define N 100
using namespace std;
int a[N],b[N];
int ans=0;
int n,r;
void f(int t,int k){
    if(k==r){
        ans++;
        for (int i = 0; i < r; i ++ ) cout << b[i] <<" ";
        puts("");
        return;
    }
    for (int i = t+1; i <= n; i ++ ){
        b[k]=a[i];
        f(i,k+1);
    }
}
int main()
{
    cin >> n >> r;
    for (int i = 1; i <= n; i ++ ) cin >> a[i];
    sort(a+1,a+1+n);
    f(0,0);
    cout<<ans;
    return 0;
}

选数(oj没有 没有AC

{{ vote && vote.total.up }}