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. 洛谷2344 奶牛抗议(DP+BIT+离散化)

    洛谷2344 奶牛抗议 本题地址:http://www.luogu.org/problem/show?pid=2344 题目背景 Generic Cow Protests, 2011 Feb 题目描述 ...

  2. RabbitMQ挂掉问题处理

    开发环境中的rabbitmq总是会挂掉,rabbitmq的执行都是ssh远程登录执行命令: rabbitmq-server & 认为加了&,进程会在后台执行不会受到终端的影响.所以不知 ...

  3. Quartz的cronTrigger表达式

    CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表.CronTr ...

  4. Qt 学习之路 :可视化显示数据库数据

    前面我们用了两个章节介绍了 Qt 提供的两种操作数据库的方法.显然,使用QSqlQuery的方式更灵活,功能更强大,而使用QSqlTableModel则更简单,更方便与 model/view 结合使用 ...

  5. [转] tomcat结合nginx使用小结

    相信很多人都听过nginx,这个小巧的东西慢慢地在吞食apache和IIS的份额.那究竟它有什么作用呢?可能很多人未必了解. 说到反向代理,可能很多人都听说,但具体什么是反向代理,很多人估计就不清楚了 ...

  6. Java笔试题二:读程序

    public class SopResult { public static void main(String[] args) { int i = 4; System.out.println(&quo ...

  7. 模板-->Guass消元法(求解多元一次方程组)

    如果有相应的OJ题目,欢迎同学们提供相应的链接 相关链接 所有模板的快速链接 简单的测试 None 代码模板 /* * TIME COMPLEXITY:O(n^3) * PARAMS: * a The ...

  8. C#学习第五天

    字符串的处理 string可作char的只读数组 下面这段字符表示访问每个字符: string myString="A string."; char myChar=myString ...

  9. 各种开发语言示例调用WebService接口

    ASP示例: <% uid="账号"pwd="密码"tos="13900041123"msg="你们好"url = ...

  10. javascript原型prototype的一个你不一定知道的理解

    原型和原型链的故事 相关文章: 为什么原型继承很重要 先来看看一段小代码用以引入要讲的小故事. function Foo() {}; var f1 = new Foo(); Foo.prototype ...