2 条题解

  • 2
    @ 2023-8-26 18:58:24
    #include<bits/stdc++.h>
    using namespace std;
    int n,a[11000][11],ans,b[11];
    bool dg(int rest,int num)
    {
        if(rest==0&&num==0)
        {
            ans++;
            for(int i=1;i<=10;i++)a[ans][i]=b[i];
            return 1;
        }
        if(rest==0)return 0;
        if(num==0)return 0;
        for(int i=1;i<=3;i++)
        {
            b[10-num+1]=i;
            dg(rest-i,num-1);
        }
        return 1;
    }
    int main()
    {
        cin>>n;
        if(n>30)
        {
            cout<<"0";
            return 0;
        }
        dg(n,10);
        cout<<ans<<endl;
        for(int i=1;i<=ans;i++)
        {
            for(int j=1;j<=10;j++)cout<<a[i][j]<<" ";
            cout<<endl;
        }
        return 0;
    }
    
    • 0
      @ 2023-8-23 21:52:40
      #include<iostream>
      using namespace std;
      int n,kind=0,m1[10000][10],m2[10];
      void peiliao(int total,int a){
          if (a==10){
              if (total==n) {
                  for (int j=0;j<10;j++) m1[kind][j]=m2[j];//符合要求存起来~~ 
                  kind++;
              }
          }
          else if (total>=n) ;//小小优化一下 
          else
            for (int i=1;i<=3;i++){
                m2[a]=i;
                peiliao(total+i,a+1);//其实这和十连for没什么区别。。。 
            }
      }
      int main(){
          cin>>n;
          peiliao(0,0);
          cout<<kind<<endl;
          for (int j=0;j<kind;j++){
            for (int i=0;i<10;i++) cout<<m1[j][i]<<" "; //大家一定要记得打空格... 
           cout<<endl; 
          }
          return 0;
      }
      
      • 1

      信息

      ID
      1047
      时间
      1000ms
      内存
      125MiB
      难度
      2
      标签
      递交数
      42
      已通过
      26
      上传者