1 条题解

  • 0
    @ 2024-12-24 9:54:35

    C :

    #include<stdio.h>
    #include<stdlib.h>
    int a[20]={1};
    int n,tot=0;
    void out(int i){
         int j;
         printf("%d=",n);
         for(j=1;j<i;j++)
             printf("%d+",a[j]);
         printf("%d\n",a[i]);
    }
    
    void search(int i,int s){
         int j;
         for(j=a[i-1];j<=s;j++)
            if(j<n) {
              a[i]=j;
              s-=j;
              if(s==0){
    		  out(i);
    		  tot++;
    		  }
              else search(i+1,s);
              s+=j;
              }
    }
    
    int main(){
        scanf("%d",&n);
        search(1,n);
        printf("%d",tot);
    
    }
    
    • 1

    信息

    ID
    1333
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者