3 条题解

  • 1
    @ 2022-10-2 9:50:20
    #include<bits/stdc++.h>
    using namespace std;
    int n,a[100],b[100],r;
    void dfs(int t){
    	if(t>n){
    		for(int i=1;i<=n;i++) cout<<setw(3)<<a[i];
    		cout<<endl;
    		return ;
    	}
    	for(int i=a[t-1]+1;i<=r;++i){
    		if(!b[i]){
    			b[i]=1;
    			a[t]=i;
    			dfs(t+1);
    			b[i]=0;
    		}
    	}
    }
    int main(){
    	cin>>r>>n;
    	dfs(1);
    }
    
    • 1
      @ 2022-10-2 9:44:46

      %%% ldh

      #include <bits/stdc++.h>
      using namespace std;
      int vis[114514], a[114514], n, r;
      void Sea(int k, int lst) {
      	if (k > r) {
      		for (int i = 1; i <= r; ++i) {
      			cout << setw(3) << a[i];
      		}
      		cout << endl;
      		return;
      	}
      	for (int i = lst + 1; i <= n; ++i) {
      		if (!vis[i]) {
      			vis[i] = true;
      			a[k] = i;
      			Sea(k + 1, i);
      			vis[i] = false;
      			a[k] = 0;
      		}
      	}
      }
      
      int main() {
      	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
      	cin >> n >> r;
      	Sea(1, 0);
      	return 0;
      }
      
      • 0
        @ 2022-7-29 20:08:56
        #include<bits/stdc++.h>
        using namespace std;
        long x[35],n,r,i,s;
        int main()
        {
            cin>>n>>r;
            for(i=r+1;i<=n;i++)x[i]=1;
            do{
                for(i=1;i<=n;i++)if(!x[i])cout<<setw(3)<<i;
                puts("");
            }while(next_permutation(x+1,x+n+1));
            return 0;
        }
        • 1

        信息

        ID
        130
        时间
        1000ms
        内存
        256MiB
        难度
        5
        标签
        (无)
        递交数
        227
        已通过
        92
        上传者