Equal Sum Sets
题目链接: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的更多相关文章
- 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 ...
- 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 ...
- UvaLive6661 Equal Sum Sets dfs或dp
UvaLive6661 PDF题目 题意:让你用1~n中k个不同的数组成s,求有多少种组法. 题解: DFS或者DP或打表. 1.DFS 由于数据范围很小,直接dfs每种组法统计个数即可. //#pr ...
- UVALive 6661 Equal Sum Sets
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- [UVALive 6661 Equal Sum Sets] (dfs 或 dp)
题意: 求从不超过 N 的正整数其中选取 K 个不同的数字,组成和为 S 的方法数. 1 <= N <= 20 1 <= K<= 10 1 <= S <= 15 ...
- HDU-3280 Equal Sum Partitions
http://acm.hdu.edu.cn/showproblem.php?pid=3280 用了简单的枚举. Equal Sum Partitions Time Limit: 2000/1000 M ...
- HDU 3280 Equal Sum Partitions(二分查找)
Equal Sum Partitions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 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 ...
- [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 ...
随机推荐
- php计算几分钟前、几小时前等
function format_date($time){ $t=time()-$time; $f=array( '=>'年', '=>'个月', '=>'星期', '=>'天' ...
- hdu 4069 福州赛区网络赛I DLC ***
再遇到一个DLC就刷个专题 #include <stdio.h> #include <string.h> #include <iostream> #include ...
- UML- 模型图介绍
第一类 用例图 第二类 静态图 类图 对象图 包图第三类 行为图 状态图 活动图第四类 交互图 序列图 协助图第五类 实现图 构件图 部署图 1 用例图:从用户角度描述系统功能,以及每个系统功 ...
- PMP 第三章 单个项目的项目管理标准
1 项目管理五大过程组分别是什么? 启动过程组 规划过程组 执行过程组 监控过程组 收尾过程组 2 启动项目组是干什么?包含哪些过程?每个阶段都需要启动吗? 启动过程组:获得授权,定义一个新项目或现有 ...
- JVM内存结构、垃圾回收那点事
翻看电脑的文件夹,无意看到了9月份在公司做的一次分享,浏览了一下"婆婆特",发现自己在ppt上的写的引导性问题自己也不能确切的回答出来,哎,知识这东西,平时不常用的没些日子就生疏了 ...
- RPC和Socket,RMI和RPC之间的关系
远程通信机制RPC与RMI的关系 http://blog.csdn.net/zolalad/article/details/25161133 1.RPC RPC(Remote Proced ...
- requireJS的使用_API(1)
之前有介绍过requireJS(模块化开发),可以看看 ,但是不详细,所以今天参考官网来详细介绍一下: 1.加载js文件: RequireJS的目标是鼓励代码的模块化,它使用了不同于传统<scr ...
- 转 : 用Delphi编写安装程序
http://www.okbase.net/doc/details/931 还没有亲自验证过,仅收藏 当你完成一个应用软件的开发后,那么你还需要为该软件做一个规范化的安装程序,这是程序设计的最后一步 ...
- JS小函数
join()\toString(): join()函数和toString()函数都是返回字符串类型. 针对一个数组: var arr = ["I","love" ...
- jquery toastr introduction
1.资源 http://www.jq22.com/jquery-info476 http://www.jq22.com/yanshi476 Nuget Install-Package toastr 官 ...