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
 
题目大意:
从 1到n中选k个数 让k个数的和为s;
 
其实就是暴力枚举
把所有的情况算出来,但是先在题目的数据还是比较大的
所以还要用到状态压缩;

 #include<iostream>
using namespace std;
int a[];
int A[];
int ans=;
void dfs(int n,int cur){
if(cur==a[]){
int sum=;
for(int i=;i<a[];i++){
sum+=A[i];
}
if(sum==a[])ans++;
}
int s=;
if(cur!=)s=A[cur-]+;
for(int i=s;i<=n;i++){
A[cur]=i;
dfs(n,cur+);
}
}
int main(){
while(cin>>a[]>>a[]>>a[]&&a[]+a[]+a[]){
ans=;
dfs(a[],);
cout<<ans<<endl;
}
return ;
}
 

Eequal sum sets的更多相关文章

  1. Aizu 1335 Eequal sum sets

    Let us consider sets of positive integers less than or equal to n. Note that all elements of a set a ...

  2. 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 ...

  3. UvaLive 6661 Equal Sum Sets (DFS)

    Let us consider sets of positive integers less than or equal to n. Note that all elements of a set a ...

  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. UVALive 6661 Equal Sum Sets

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

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

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

  8. Project Euler P105:Special subset sums: testing 特殊的子集和 检验

    Special subset sums: testing Let S(A) represent the sum of elements in set A of size n. We shall cal ...

  9. Project Euler 103:Special subset sums: optimum 特殊的子集和:最优解

    Special subset sums: optimum Let S(A) represent the sum of elements in set A of size n. We shall cal ...

随机推荐

  1. Struts+Tomcat搭建

    Struts+Tomcat搭建 tomcat使用(服务器端开发): 如果要安装Tomcat需要进行的配置:tomcat安装在c: \Tomcat CATALINA_HOME变量值设为: H:\Prog ...

  2. java中将list、map对象写入文件

    链接地址:http://blog.sina.com.cn/s/blog_4a4f9fb50101p6jv.html     推荐:凤爪女瓜子男怪象该谁反思伦敦房价为什么持续暴涨 × wvqusrtg个 ...

  3. Hadoop伪分布式模式部署

    Hadoop的安装有三种执行模式: 单机模式(Local (Standalone) Mode):Hadoop的默认模式,0配置.Hadoop执行在一个Java进程中.使用本地文件系统.不使用HDFS, ...

  4. 个人mysql配置命令

    Microsoft Windows [版本 6.1.7601]版权所有 (c) 2009 Microsoft Corporation.保留所有权利. C:\Windows\system32>cd ...

  5. VS2013 Qt5 Mysql中文编码问题

    Qt开始默认是utf-8,而VS2013默认程序编码为gb2312: 这样就会发现使用中文的时候乱码. 一般有二种解决方案: 1.在使用中文的时候,使用QTextCodec QTextCodec *g ...

  6. QThread 与 QObject的关系(QObject可以用于多线程,可以发送信号调用存在于其他线程的slot函数,但GUI类不可重入)

    QThread 继承 QObject..它可以发送started和finished信号,也提供了一些slot函数. QObject.可以用于多线程,可以发送信号调用存在于其他线程的slot函数,也可以 ...

  7. android handler looper thread

    在线程中调用包含创建handler方法的时候,会报错,提示: “need call Looper.prepare()” -- 在创建之前,调用Looper.prepare()方法来创建一个looper ...

  8. 利用java concurrent 包实现日志写数据库的并发处理

    一.概述 在很多系统中,往往需要将各种操作写入数据库(比如客户端发起的操作). 最简单的做法是,封装一个公共的写日志的api,各个操作中调用该api完成自己操作日志的入库.但因为入数据库效率比较低,如 ...

  9. 服务列表 - Sina App Engine

    服务列表 - Sina App Engine 短信服务 新浪无线短信服务是由新浪无线提供的综合性短信服务. 使用服务 下载SDK: php 服务首页 方法 新浪无线短信服务是由新浪无线提供的综合性短信 ...

  10. JIRA初步

    JIRA 是澳大利亚 Atlassian 公司开发的一款优秀的问题跟踪管理软件工具.可以对各种类型的问题进行跟踪管理.包含缺陷.任务.需求.改进等.JIRA採用J2EE技术.可以跨平台部署.它正被广泛 ...