题目链接: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. 随机生成字符串-php-js

    js <script language="javascript"> function randomString(len) { len = len || 32; var ...

  2. 11g添加asm

    1.创建组 2.创建grid用户 3.用grid安装Gride Infrastructure软件 4.执行root.sh[root@ora11g softdb]# /u01/app/11.2.0/gr ...

  3. vs2015 MFC工程添加消息响应函数

    真不知道这PPT怎么描述的..最后窝找到了解决方法如上图.. 下次找MSDN解决问题好了..而且我们并不知道他所说的这个IDE到底是哪个厂商哪个版本的IDE这就很困惑 不过呢..它主要是让我们添加消息 ...

  4. ImageSpan

    自定义ImageSpan继承类,可以设置图片大小和位置 import android.content.Context; import android.graphics.Bitmap; import a ...

  5. 解决android expandablelistview 里面嵌入gridview行数据重复问题

    最近做了一个“csdn专家博客App” 当然了是android版本,在专家浏览页面,我才用了expandablelistview 组件来显示专家分类,每个分类点击之后可以显示专家的头像和名字. 很简单 ...

  6. Loadrunner的自定义监控器

    Loadrunner的自定义监控器 可以使用lr_user_data_point()来实现自定义监控,下面是一个小例子: double showsomething(); Action(){ doubl ...

  7. Liferay 6.2 改造系列之九:修改用户信息填写规则

    为了让用户信息更贴近实际需求,修改如下信息: 1.让登录名可以使用数字.“.”.“_”等 在/portal-master/portal-impl/src/portal.properties文件中,有如 ...

  8. 简单的c#插件框架

    插件式架构,一种全新的.开放性的.高扩展性的架构体系.插件式架构设计近年来非常流行,基于插件的设计好处很多,把扩展功能从框架中剥离出来,降低了框架的复杂度,让框架更容易实现.扩展功能与框架以一种很松的 ...

  9. ios开发学习笔记(这里一定有你想要的东西,全部免费)

    1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现clear Color无法使用). 其实在代码里还是可以设置的,那就是删除背景view [ ...

  10. Hi,我还没死(屎)

    HDNOIP没考好,紧接着NOIP又到了,加紧练习:-)