题意:传送门

题目描述

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. PostgreSQL 配置远程访问

    配置远 程连接PostgreSQL数据库的步骤很简单,只需要修改data目录下的pg_hba.conf和postgresql.conf. pg_hba.conf:配置对数据库的访问权限, postgr ...

  2. 超简单CSS3实现圆角、阴影、透明效果

    CSS实现圆角,阴影,透明的方法很多,传统的方法都比较复杂,用CSS3就方便很多了,虽然现在各浏览器对CSS3的支持还不是很好,但不久的将来CSS3就会普及. 1.圆角 CSS3实现圆角有两种方法. ...

  3. Ubuntu 16.04 更换阿里云源

    Ubuntu 16.04 更换阿里云源sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #备份sudo gedit /etc/apt/so ...

  4. 【BZOJ】1682: [Usaco2005 Mar]Out of Hay 干草危机(kruskal)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1682 最小生成树裸题.. #include <cstdio> #include < ...

  5. 自动化测试的组成部分:SEARCH

    在考虑自动化测试用例时,不仅仅要考虑测试的执行步骤.在运行任何步骤之前,程序必须处在能够执行测试的状态.在测试执行后,至关重要的是知道测试是否通过,并且测试结果一定要被保存到某处以待检查或进一步分析. ...

  6. [转]Tcpcopy简介与实战

    Tcpcopy简介 TCPCopy是一种请求复制(所有基于tcp的packets)工具 ,其功能是复制在线数据包,修改TCP/IP头部信息,发送给测试服务器,达到欺骗测试服务器的TCP 程序的目的,从 ...

  7. Hive将txt、csv等文本文件导入hive表

    1.将txt文本文件放置hdfs目录下 2.登录hive并进入到指定数据库 3.创建表 create external table if not exists fun_user_external ( ...

  8. C# winform 中MessageBox用法大全(附效果图)

    我们在程序中经常会用到MessageBox. MessageBox.Show()共有21中重载方法.现将其常见用法总结如下: 1.MessageBox.Show(“Hello~~~~”); 最简单的, ...

  9. LinCode落单的数

    easy 落单的数 查看执行结果 60% 通过 给出2*n + 1 个的数字,除当中一个数字之外其它每一个数字均出现两次.找到这个数字. 您在真实的面试中是否遇到过这个题? Yes 例子 给出 [1, ...

  10. Java各种日期格式的获取和设置指定日期

    因为近期在做一个项目,发现项目中日期设置的bug,于是查阅了多方资料后.最终攻克了,为此写篇总结.方便日后的查阅. 多的不说了.直接上代码 package com.example.testdate; ...