Let us consider sets of positive integers less than or equal to n. Note that all elements of a set are different. Also note that the order of elements doesnt matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set.

Specifying the number of set elements and their sum to be k and s, respectively, sets satisfying the conditions are limited. When n = 9, k = 3 and s = 23, {6, 8, 9} is the only such set. There may be more than one such set, in general, however. When n = 9, k = 3 and s = 22, both {5, 8, 9} and {6, 7, 9} are possible.

You have to write a program that calculates the number of the sets that satisfy the given conditions.

Input

The input consists of multiple datasets. The number of datasets does not exceed 100. Each of the datasets has three integers n, k and s in one line, separated by a space. You may assume 1 ≤ n ≤ 20, 1 ≤ k ≤ 10 and 1 ≤ s ≤ 155. The end of the input is indicated by a line containing three zeros.

Output The output for each dataset should be a line containing a single integer that gives the number of the sets that satisfy the conditions. No other characters should appear in the output. You can assume that the number of sets does not exceed 231 − 1.

Sample Input

9 3 23

9 3 22

10 3 28

16 10 107

20 8 102

20 10 105

20 10 155

3 4 3

4 2 11

0 0 0

Sample Output

1

2

0

20

1542

5448

1

0

0

题意:

求从不超过 N 的正整数当中选取 K 个不同的数字,组成和为 S 的方法数。

1 <= N <= 20  1 <= K<= 10  1 <= S <= 155

AC代码

#include<iostream>
using namespace std;
int n,k,s,total;
void dfs(int x,int y,int z)
{
if(y==k&&z==s)
{
total++;
return;
}
for(int i=; i<=x-; i++)
{
if(z+i<=s)
dfs(i,y+,z+i);
}
}
int main()
{
while(cin>>n>>k>>s&&n&&k&&s)
{
total=;
dfs(n+,,);
cout<<total<<endl;
}
return ;
}

UvaLive 6661 Equal Sum Sets (DFS)的更多相关文章

  1. [UVALive 6661 Equal Sum Sets] (dfs 或 dp)

    题意: 求从不超过 N 的正整数其中选取 K 个不同的数字,组成和为 S 的方法数. 1 <= N <= 20  1 <= K<= 10  1 <= S <= 15 ...

  2. UVALive 6661 Equal Sum Sets

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  3. D.6661 - Equal Sum Sets

    Equal Sum Sets Let us consider sets of positive integers less than or equal to n. Note that all elem ...

  4. UvaLive6661 Equal Sum Sets dfs或dp

    UvaLive6661 PDF题目 题意:让你用1~n中k个不同的数组成s,求有多少种组法. 题解: DFS或者DP或打表. 1.DFS 由于数据范围很小,直接dfs每种组法统计个数即可. //#pr ...

  5. Equal Sum Sets

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=49406 题意: 输入n,k,s,求在不小于n的数中找出k个不同的数 ...

  6. HDU-3280 Equal Sum Partitions

    http://acm.hdu.edu.cn/showproblem.php?pid=3280 用了简单的枚举. Equal Sum Partitions Time Limit: 2000/1000 M ...

  7. 698. Partition to K Equal Sum Subsets

    Given an array of integers nums and a positive integer k, find whether it's possible to divide this ...

  8. HDU 3280 Equal Sum Partitions(二分查找)

    Equal Sum Partitions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  9. [LeetCode] 548. Split Array with Equal Sum 分割数组成和相同的子数组

    Given an array with n integers, you need to find if there are triplets (i, j, k) which satisfies fol ...

随机推荐

  1. 《A First Course in Probability》-chaper5-连续型随机变量-均匀随机变量

    在连续随机变量这部分,有一种特殊的随机变量X,对于X所有可能取值,P(X)都相等,我们称其为均匀随机变量. 基于均匀随机变量的定义,我们容易看到,其密度函数f(x)必然是一条平行于x轴的直线,因为这样 ...

  2. HTML参考手册

    New : HTML5 中的新标签. 标签 描述 <!--...--> 定义注释. <!DOCTYPE>  定义文档类型. <a> 定义锚. <abbr> ...

  3. XQuery FLWOR 表达式

    FLWOR 是 "For, Let, Where, Order by, Return" 的只取首字母缩写.for 语句把 bookstore 元素下的所有 book 元素提取到名为 ...

  4. Mybatis+SpringMVC实现分页查询(附源码)

    Maven+Mybatis+Spring+SpringMVC实现分页查询(附源码) 一.项目搭建 关于项目搭建,小宝鸽以前写过一篇Spirng+SpringMVC+Maven+Mybatis+MySQ ...

  5. Fiddler 抓包 教程

    Fiddler的基本介绍 Fiddler的官方网站:  www.fiddler2.com Fiddler官方网站提供了大量的帮助文档和视频教程, 这是学习Fiddler的最好资料. Fiddler是最 ...

  6. JAVA大数类

    JAVA大数类api http://man.ddvip.com/program/java_api_zh/java/math/BigInteger.html#method_summary 不仅仅只能查J ...

  7. [置顶] poj1416数字切割解题报告

    题意:有一段纸片,就是一个不超过7位数的整数,现在给定你一个目标值 aim ,让你去选择把纸片切成几段,然后这个几段的和值 最接近 aim 且不超过 aim, 分析: 对于这个纸段,比如一个 四位数的 ...

  8. OpenStack Cinder源代码流程简析

    版权声明:本博客欢迎转载,转载时请以超链接形式标明文章原始出处!谢谢! 博客地址:http://blog.csdn.net/i_chips 一.概况 OpenStack的各个模块都有对应的client ...

  9. 浅析mysql 共享表空间与独享表空间以及他们之间的转化

        innodb这种引擎,与MYISAM引擎的区别很大.特别是它的数据存储格式等.对于innodb的数据结构,首先要解决两个概念性的问题: 共享表空间以及独占表空间.什么是共享表空间和独占表空间共 ...

  10. MVC实现登录,增删改查之数据展示:JSP的EL表达式(二)

    这里的数据展示利用jsp的EL表达式,后台放入session,前台EL获取 数据库设计是这样的,一个老师对应有多个学生,在学生表student中建立外键tid与老师表teacher的tid对应,现在老 ...