跳至正文

1 条题解

  • 0
    @ 2026-10-2 2:21:53

    用setw(3)输出所有组合中的每个数,修复两位整数占四格的问题。

    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){ios::sync_with_stdio(false);cin.tie(nullptr);
    
    int n,r;cin>>n>>r;vector<int>path;function<void(int)>dfs=[&](int next){if((int)path.size()==r){for(int x:path)cout<<setw(3)<<x;cout<<"\n";return;}int remaining=r-path.size();for(int x=next;x<=n-remaining+1;x++){path.push_back(x);dfs(x+1);path.pop_back();}};dfs(1);
    
    return 0;
    }
    
    • 1

    信息

    ID
    3992
    时间
    1000ms
    内存
    128MiB
    难度
    5
    标签
    递交数
    0
    已通过
    0
    上传者