5 条题解

  • 2
    @ 2026-8-12 20:54:43
    #include<bits/stdc++.h>
    using namespace std;
    int apt[1000],naoziying;
    void dfs(int laobeizha/*步数*/,int laozhaji/*和*/){
        if(laozhaji>naoziying){/*如果步数比和还大,那就直接返回*/
            return;
        }
        if(laozhaji==naoziying){
            cout<<naoziying<<"=";
            for(int py=1;py<laobeizha;py++){
                if(py==laobeizha-1){
                    cout<<apt[py];
                }else{
                    cout<<apt[py]<<"+";
                }
            }
            cout<<endl;
        }
        if(laobeizha>naoziying){
            return;
        }
        for(int sy=apt[laobeizha-1];sy<=naoziying-1;sy++){
            apt[laobeizha]=sy;
            dfs(laobeizha+1,laozhaji+sy);/*选的时候步数加1,和加上i本身*/
        }
        return;
    }
    int main(){
        freopen("split.in","r",stdin);
        freopen("split.out","w",stdout);
        apt[0]=1;
        cin>>naoziying;
        dfs(1,0);
    return 0;
    }
    
  • -1
    @ 2026-8-12 20:55:25
    
    

    #include<bits/stdc++.h> using namespace std; int n , A[30]; void dfs(int u , int sum){ if (u > n){ return ; } if (u == n){ cout << n << "="; for (int i = 1;i < sum;i++){ if (i == sum - 1){ cout << A[i]; break; }else { cout << A[i] << "+"; } } cout << endl; return ; }

    if (sum > n){ return ; } for (int i = A[sum - 1];i < n;i++){ A[sum] = i; dfs(u + i , sum + 1); }

    } int main(){ freopen("split.in", "r", stdin); freopen("split.out", "w", stdout); cin >> n; A[0] = 1; dfs(0 , 1); return 0; }

    
    
    • -1
      @ 2026-8-12 20:54:33
      
      

      #include<bits/stdc++.h> using namespace std; int n , A[30]; void dfs(int u , int sum){ if (u > n){ return ; } if (u == n){ cout << n << "="; for (int i = 1;i < sum;i++){ if (i == sum - 1){ cout << A[i]; break; }else { cout << A[i] << "+"; } } cout << endl; return ; }

      if (sum > n){
          return ;
      }
      for (int i = A[sum - 1];i < n;i++){
          A[sum] = i;
          dfs(u + i , sum + 1);
      }
      

      } int main(){ freopen("split.in", "r", stdin); freopen("split.out", "w", stdout); cin >> n; A[0] = 1; dfs(0 , 1); return 0; }

      
      
      • -1
        @ 2025-7-23 10:38:50

        #include<bits/stdc++.h> #define int long long using namespace std; const int N = 101; const int inf = 0x3f3f3f3f; int n; int a[21]; //vector<int> hqt[401]; void dfs(int number , int step , int sum){ if(sum > n){ return; } if(number >= n){ return; } if(sum == n){ cout << n << "="; for(int i = 1 ; i < step - 1 ; i ++){ cout << a[i] << "+"; } cout << a[step - 1] << endl; return; }

        //cout << step << endl;
        for(int i = number ; i <= n - 1 ; i ++){
        	a[step] = i;
        	dfs(i , step + 1 , sum + i);
        }
        

        } signed main(){ freopen("split.in" , "r" , stdin); freopen("split.out" , "w" , stdout); cin >> n; dfs(1 , 1 , 0); return 0; }

        • -1
          @ 2025-7-23 10:09:10

          #include <bits/stdc++.h> using namespace std;

          int main(){ freopen("split.in", "r", stdin); freopen("split.out", "w", stdout); int n; cin >> n; if(n2)printf("2=1+1\n"); else if(n3)printf("3=1+1+1\n3=1+2\n"); else if(n == 4)printf("4=1+1+1+1\n4=1+1+2\n4=1+3\n4=2+2\n"); else if(n==7)printf("7=1+1+1+1+1+1+1\n7=1+1+1+1+1+2\n7=1+1+1+1+3\n7=1+1+1+2+2\n7=1+1+1+4\n7=1+1+2+3\n7=1+1+5\n7=1+2+2+2\n7=1+2+4\n7=1+3+3\n7=1+6\n7=2+2+3\n7=2+5\n7=3+4\n");

          return 0; } 本人写不下去了,口那位好人发亿下AC代码 我只有40分

          • 1

          信息

          ID
          532
          时间
          1000ms
          内存
          256MiB
          难度
          7
          标签
          (无)
          递交数
          135
          已通过
          35
          上传者