2 条题解

  • 0
    @ 2023-12-9 16:34:46
    //Author:TZR087
    #include<bits/stdc++.h>
    using namespace std;
    string ans="11451419198101145141919810",s;
    int n,m,a[105][105];
    bool check(int dep){
    	for(int i=1;i<dep;i++)
    		if(a[i]==a[dep])return 0;
    	return 1;
    }
    void work(int dep){
    	if(dep>n){
    		s="";
    		for(int i=1;i<=n;i++){
    			a[1][i]=ans[i-1]^48;
    		}
    		for(int i=2;i<=n;i++){
    			for(int j=1;j<=n-i+1;j++){
    				a[i][j]=a[i-1][j]+a[i-1][j+1];
    			}
    		}
    		if(a[n][1]<m){
    			ans=min(ans,s);
    		}
    	}
    	for(int i=1;i<=n;i++){
    		s+=char(i^48);
    		work(dep+1);
    	}
    }
    int main(){
    	cin>>n>>m;
    	work(1);
    	cout<<ans[0];
    	for(int i=1;i<ans.size();i++){
    		cout<<" "<<ans[i];
    	}
    	return 0;
    }
    
    
    • -1
      @ 2023-12-17 11:45:13

      #include<bits/stdc++.h>

      using namespace std;

      int a[101],b[101],n,k; void check(int dep){

      if(dep>n){
      
      
      	if(b[1]==k){
      		for(int i=1;i<n;i++)cout<<a[i]<<" ";
      
      		cout<<a[n];
      
      		exit(0);
      
      	}
      
      	return;
      
      }
      
      for(int i=1;i<=n-dep+1;i++)b[i]=b[i]+b[i+1];
      
      check(dep+1);
      

      }

      int main(){

      cin>>n>>k;
      
      for(int i=1;i<=n;i++)a[i]=i;
      
      do{
      
      	for(int i=1;i<=n;i++)b[i]=a[i];
      
      	check(2);
      
      }while(next_permutation(a+1,a+1+n));
      
      return 0;
      

      } //zhaochenhe //绝对不会错,我说的

      • 1

      信息

      ID
      783
      时间
      1000ms
      内存
      256MiB
      难度
      3
      标签
      递交数
      21
      已通过
      11
      上传者