题目链接: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. BRIEF 特征描述子

    Binary Robust Independent Elementary Features www.cnblogs.com/ronny 1. BRIEF的基本原理 我们已经知道SIFT特征采用了128 ...

  2. NSArray 所有基础点示例

    #import <Foundation/Foundation.h> //排序算法,应用于 NSArray *arr=[arrs1 sortedArrayUsingFunction:sort ...

  3. SurfaceView

    我们先来看下官方API对SurfaceView的介绍 SurfaceView的API介绍 Provides a dedicated drawing surface embedded inside of ...

  4. 面向对象中this问题

    this什么时候会出错? 注意:其中var _this = this 的巧妙用法. 1.定时器: <script type="text/javascript"> //如 ...

  5. JMeter中的关联-正则表达式提取(2)

    JMeter获取正则表达式中的提取的所有关联值的解决方法: 需求如下: { : ", : "results": : [ : : { : : : "total_e ...

  6. Loadrunner的自定义监控器

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

  7. Problem list

    不定时更新,发现好题目但是没时间写的就添加,写完就删除. hdu5732 求树的重心 poj1741

  8. 农资产品送货车上使用 PDA手持机 现场销售开单 然后开单后能直接通过移动网络传回电脑(云服务器)

    客户挑战与需求 目前很多中小型企业或零售商店都会使用各种进销存管理软件以提高管理效率,但是由于这类软件都是安装在PC端,更多的是帮助客户通过进销存的管理分析企业营运账款,并不能实时地反映当前销售.库存 ...

  9. [bzoj1071]组队[单调指针乱搞]

    这道题也很感人,主要改了比较久的时间... bzoj第一页的题,居然只过了五百多个人,(我是第512,orzliyicheng是513) 代码不长,但是细节搞了很久,主要sort写错了,晕... 首先 ...

  10. maven工程下 读取resource下配置文件

    http://blog.csdn.net/xu511739113/article/details/52440982