题目链接: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. window.location.href和window.location.replace的区别

    有3个html页面(.html, .html, .html). 进系统默认的是1.html ,当我进入2.html的时候, .html里面用window.location.replace(" ...

  2. ServerSocket 默认邦定IP

    转自:http://cuisuqiang.iteye.com/blog/2037769 开发中需要开启服务端的时候,本地测试都是直接写端口,实际环境也是需要指定要邦定的IP才可以. 因为对于服务器来说 ...

  3. poj 3264 【线段树】

    此题为入门级线段树 题意:给定Q(1<=Q<=200000)个数A1A2…AQ,多次求任一区间Ai-Aj中最大数和最小数的差 #include<algorithm> #incl ...

  4. Arduino101学习(一)——Windows下环境配置

    一.Arduino IDE下载 要开发Arduino 101/Genuino 101,你需要先安装并配置好相应的开发环境.下载地址 http://www.arduino.cn/thread-5838- ...

  5. 通信原理实践(二)——幅度调制

    一.幅度调制,并画出时域和频域波形 1.代码如下: function [ p_n ] = AM_func( N,fs,fm,Am,fc,Ac,Ma ) %UNTITLED 此处显示有关此函数的摘要 % ...

  6. jQuery方法注意事项

    1.关于选择器中含有特殊符号 选择器中含有".","#","(","]"等特殊字符,根据W3C的规定,属性值中是不能含有 ...

  7. Angular JS 学习之Http

    1.$http是AngularJS中的一个核心服务,用于读取远程服务器的数据: 2.读取JSON文件: **JSON文件如下: { "sites":[ { "Name&q ...

  8. [转载] Spring MVC - 处理器拦截器

    5.1.处理器拦截器简介 Spring Web MVC的处理器拦截器(如无特殊说明,下文所说的拦截器即处理器拦截器)类似于Servlet开发中的过滤器Filter,用于对处理器进行预处理和后处理.   ...

  9. static方法中为什么使用的都是静态变量

    static方法中需要使用静态变量.假设其他类要使用该方法,该方法里面所使用的变量是非静态的,如果该方法所在的类没有实例化,会导致该方法里面的变量不能实例化,自然该static 方法不能使用

  10. Android视频

    http://mars.apkbus.com/ http://dl.dbank.com/c0y2tnjnxz csdn http://blog.csdn.net/softwave/article/ca ...