题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=49406

题意:

输入n,k,s,求在不小于n的数中找出k个不同的数的和等于s的可能性有多少种。

样例:

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

分析:

用递推的方法把所有的值先求出来,保存到一个数组中,然后直接输出所求值即可。

公式:d[n][k][s]=d[n-1][k][s]+d[n-1][k-1][s-1]   s>=n时

d[n][k][s]=d[n-1][k][s]    s<n时

 #include<iostream>
#include<cstring>
using namespace std;
int i,d[][][],sum;
void db()
{
memset(d,,sizeof(d));
//一些特殊值
for( i=;i<=;i++)
{
d[i][][i]=;
d[i][][]=;
}
for( i=;i<=;i++)
{
for(int k=;k<=;k++)
{
if(k>i) break; //不可能有集合满足
for(int s=;s<=;s++)
{
sum=;
sum=sum+d[i-][k][s];
if(s>=i) sum=sum+d[i-][k-][s-i];
d[i][k][s]=sum;
}
}
}
return;
}
int main()
{
db();
int n,k,s;
cin>>n>>k>>s;
while(n&&k&&s)
{
cout<<d[n][k][s]<<endl;
cin>>n>>k>>s;
}
return ;
}

Equal Sum Sets的更多相关文章

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

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

  3. UvaLive6661 Equal Sum Sets dfs或dp

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

  4. UVALive 6661 Equal Sum Sets

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

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

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

  6. HDU-3280 Equal Sum Partitions

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

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

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

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

  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. HR外包系统 - 员工项目 薪资项目 考勤项目 -管理

    项目管理-包括员工项目 薪资项目 考勤项目 一 后台总公司定义项目-前台分公司选择项目,定义别名-分公司客户选择员工项目,定义别名 分公司下面-新建薪资类别-薪资类别下面选择要的薪资和考勤项目. 二 ...

  2. hdu 4770(枚举 + dfs爆搜)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4770 思路:由于最多只有15个".",可以直接枚举放置的位置,然后判断是否能够全部 ...

  3. LoadRunner关联之学习笔记

    去银行办业务,进银行的门,大堂经理给你一张业务号,拿着这张业务号,去柜台办理业务.--录制下来 第二天又去银行,还是拿着这张业务号,去柜台办理业务,柜员就不理你了,因为这张业务号是昨天的.--回放过程 ...

  4. 【JSON 注解】JSON循环引用2----JSON注解@JsonIgnoreProperties+JAVA关键字transient+后台对象与JSON数据的格式互相转化

    接着来说这个JSON循环引用的问题: 关于JSON格式的转化,其实关键就是这几个依赖: <!-- json --> <!-- 1号 --> <dependency> ...

  5. Android开发之ViewPager+ActionBar+Fragment实现响应式可滑动Tab

     今天我们要实现的这个效果呢,在Android的应用中十分地常见,我们可以看到下面两张图,无论是系统内置的联系人应用,还是AnyView的阅读器应用,我们总能找到这样的影子,当我们滑动屏幕时,Tab可 ...

  6. SpringMyBatis解析2-SqlSessionFactoryBean

    通过分析整合示例中的配置文件,我们可以知道配置的bean其实是成树状结构的,而在树的最顶层是类型为org.mybatis.spring.SqlSessionFactoryBean的bean,它将其他相 ...

  7. ccpc_南阳 C The Battle of chibi dp + 树状数组

    题意:给你一个n个数的序列,要求从中找出含m个数的严格递增子序列,求能找出多少种不同的方案 dp[i][j]表示以第i个数结尾,形成的严格递增子序列长度为j的方案数 那么最终的答案应该就是sigma( ...

  8. jQuery WipeTouch

    有时,当你只想为触屏划动添加事件时,很多人可能会想到,Jquery mobile,但就这么个功能就把人家这么高大上的东西引用进来就有点大才小用了,WipeTouch是国外某程序员写的针对触屏划动的jq ...

  9. Zookeeper 3.4.6 Client端流程粗略梳理

    首先从Zookeeper入手,Zookeeper-->ClientCnxn-->sendThread/eventThread public ZooKeeper(String connect ...

  10. 【原】iOS多线程之异步任务+并行队列情况与异步任务+串行队列(主队列)情况

    异步任务+并行队列 把异步任务放到并行队列进行执行,异步任务会在不同的线程中执行. /*异步执行+并行队列*/ - (IBAction)clickBasic1:(UIButton *)sender { ...