点击这里更换您喜欢的皮肤wtboj 首页
请点击这里登入noios   首页 入门 c++讲义 入门教程视频 金牌教程 入门视频 站务 公告 | 题库 记录 竞测 测试 闯关 作业 排名 团队 讨论 | 换肤 | 登入 注册  
News >>   新增功能:各团队管理员可以发布本团队作业了 ()

From sina002
A+B Problem
讨论 Discussion
 
1554答案
#include <bits/stdc++.h>
using namespace std;
freopen("1554.in","r",stdin);
freopen("1554.out","w",stdout);
void printCombinations(int n, int r) {
  vector<int> comb(r);
  for (int i = 0; i < r; ++i) {
    comb[i] = i + 1;
  }

  while (true) {
    for (int i = 0; i < r; ++i) {
      if (i != 0) cout << " ";
      cout << comb[i];
    }
    cout << endl;

    int pos = r - 1;
    while (pos >= 0 && comb[pos] == n - r + pos + 1) {
      --pos;
    }

    if (pos < 0) break;
    ++comb[pos];
    for (int i = pos + 1; i < r; ++i) {
      comb[i] = comb[i - 1] + 1;
    }
  }
}

int main() {
  int n, r;
  cin >> n >> r;
  printCombinations(n, r);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
( )

此主题无回复显示
发布讨论主题 回复讨论主题
Flag
  
题号
  P1000
  其它
通过
  399人
提交
  3310次
通过率
  12%
难度
  0
提交 讨论 题解
 Copyright wtboj © 2005-2006. www.wutuobang.date Powered by wtboj 关于 联系 帮助
 wtboj Information ---- Total Users : 1363 | Online Users / Processes : 0 / 46 | Processed Time : 66 ms | Server Time : 2025/12/18 15:42:15