题意:传送门

题目描述

As you know, shadow95 is pretty good at maths, especially combinatorial mathematics. Now, he has made a problem for you. We call a subset which exactly has r elements as a "r-subset".For example, {1,2,5} is a 3-subset(r=3) of {1,2,3,4,5}. Now, your task is to form all the r-subset of {1,2,...,n}, then output them in lexicographic order(字典序).

输入

 The input file ends by EOF.

For each test case, there are two integer n,r.(1 <= r < n <= 20)

输出

 First output the case number, then output all the r-subset of {1,2,...,n} in lexicographic order.

Each case seperates by a blank line.

示例输入

3 2
3 1

示例输出

Case #1:
1 2
1 3
2 3 Case #2:
1
2
3
题目很简单,代码很快就敲出来了,令人伤心的是PE无数遍,因为之前的题都没卡那么严,遇到这种输出格式错误慌了.......
每组数据之后有一个空行,但是最后一组数据没有空行,如果只输入一组n,m,那么之后不需要打印空行。
具体请看代码:
#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <stack>
#define inf 0x3f3f3f3f
#include <stdio.h>
#include <string.h>
typedef long long ll;
#define mod 10000007
#define eps 1e-9
using namespace std;
int n,r,a[];
void dfs(int k,int step)
{
a[step]=k;
if(step>r) return ;
if(step==r)
{
for(int i=; i<=step; i++)
{
if(i==) printf("%d",a[i]);
else printf(" %d",a[i]);
}
printf("\n");
}
for(int i=k+; i<=n; i++)
dfs(i,step+);
}
int main()
{
int K=;
while(scanf("%d%d",&n,&r)!=EOF)
{
if(K>=1) printf("\n");//这样能避免PE
printf("Case #%d:\n",++K);
for(int i=; i<=n-r+; i++)
dfs(i,);
}
return ;
}

SDUT3143:Combinatorial mathematics(组合数学)的更多相关文章

  1. [LeetCode] Find the Derangement of An Array 找数组的错排

    In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no ...

  2. 【转】科大校长给数学系学弟学妹的忠告&本科数学参考书

    1.老老实实把课本上的题目做完.其实说科大的课本难,我以为这话不完整.科大的教材,就数学系而言还是讲得挺清楚的,难的是后面的习题.事实上做1道难题的收获是做10道简单题所不能比的. 2.每门数学必修课 ...

  3. slot游戏中的数学概念

    最近研究slot 算法,看了大量的英文资料,因为母语中文,一直使用中文的英文小白来说,好心塞,悔不当初没学好英文. 下文是从众多的英文中摘录的唯一能够看明白的概念.先给自己留着,到时候深入研究可以看 ...

  4. SCI&EI 英文PAPER投稿经验【转】

    英文投稿的一点经验[转载] From: http://chl033.woku.com/article/2893317.html 1. 首先一定要注意杂志的发表范围, 超出范围的千万别投,要不就是浪费时 ...

  5. 一位学长的ACM总结(感触颇深)

    发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...

  6. [leetcode-634-Find the Derangement of An Array]

    In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no ...

  7. Something-Summary

    1.Combinatorial Mathematics 1.1 Bell Number: \(B_n\)表示元素个数为n的集合划分成若干个不相交集合的方案数. \(B_{n + 1} = \sum_{ ...

  8. 德布鲁因序列与indexing 1

    目录 写在前面 标记left-most 1与right-most 1 确定位置 德布鲁因序列(De Bruijn sequence) 德布鲁因序列的使用 德布鲁因序列的生成与索引表的构建 参考 博客: ...

  9. What Is Mathematics?

    What Is Mathematics? The National Council of Teachers of Mathematics (NCTM), the world's largest org ...

随机推荐

  1. dp - HNU 13404 The Imp

    The Imp Problem's Link: http://acm.hnu.cn/online/?action=problem&type=show&id=13404&cour ...

  2. NodeJS与Javascript时代

    如果你一直在关注互联网的相关技术,你应该会有这样一种感觉,web技术正在发生着变革,虽然我们不愿相信,但一个事实已经越来越清晰的摆在了眼前:LAMP组合的时代将要成为历史,在web诞生的二十年间,它影 ...

  3. Hadoop家族系列文章

    转自:http://blog.fens.me/series-hadoop-family/ Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Hadoop, Hive, Pig, H ...

  4. 【vijos】1006 晴天小猪历险记之Hill(dijkstra)

    https://vijos.org/p/1006 连边后跑点权的最短路 注意连边的时候左端点可以连到下一行的右端点,右端点可以连到下一行的左端点 #include <cstdio> #in ...

  5. thinkPHP中phpexcel的导出功能

    public function wExcel() { vendor("PHPExcel.PHPExcel"); // Create new PHPExcel object $obj ...

  6. MyBitis(iBitis)系列随笔之二:类型别名(typeAliases)与表-对象映射(ORM)

    类型别名(typeAliases):     作用:通过一个简单的别名来表示一个冗长的类型,这样可以降低复杂度.    类型别名标签typeAliases中可以包含多个typeAlias,如下 < ...

  7. AWS系列-复制AMI到其他区域

    复制AMI镜像到其他区域 1.1 打开EC2控制面板,找到AMI 选择需要迁移的AMI 1.2 选择复制的目标区域 选择复制到目标区域 我这里是 东京复制到新加坡 1.3 点击完成后,切换到相应的区域 ...

  8. C语言数组元素的查询

    在实际开发中,经常需要查询数组中的元素.例如,学校为每位同学分配了一个唯一的编号,现在有一个数组,保存了实验班所有同学的编号信息,如果有家长想知道他的孩子是否进入了实验班,只要提供孩子的编号就可以,如 ...

  9. IOS内购支付服务器验证模式

    IOS 内购支付两种模式: 内置模式 服务器模式 内置模式的流程: app从app store 获取产品信息 用户选择需要购买的产品 app发送支付请求到app store app store 处理支 ...

  10. Arduino开发版学习计划--蜂鸣器

    文章内容参考:http://www.cnblogs.com/xiaowuyi/p/3343757.html 遇到不懂的方法,可以查看Arduino自带的API 就直接点击arduino的IDE里面菜单 ...