Marks Distribution

Time limit: 3.000 seconds

In an examination one student appeared in N subjects and has got total T marks. He has passed in all the Nsubjects where minimum mark for passing in each subject is P. You have to calculate the number of ways the student can get the marks. For example, if N=3T=34 and P=10 then the marks in the three subject could be as follows.

 

Subject 1

Subject 2

Subject 3

1

14

10

10

2

13

11

10

3

13

10

11

4

12

11

11

5

12

10

12

6

11

11

12

7

11

10

13

8

10

11

13

9

10

10

14

10

11

12

11

11

10

12

12

12

12

12

10

13

10

13

11

14

11

13

10

15

10

14

10

So there are 15 solutions. So F (3, 34, 10) = 15.

Input

In the first line of the input there will be a single positive integer K followed by K lines each containing a single test case. Each test case contains three positive integers denoting NT and P respectively. The values of NT and P will be at most 70. You may assume that the final answer will fit in a standard 32-bit integer.

Output

For each input, print in a line the value of F (N, T, P).

Sample Input

Output for Sample Input

2
3 34 10
3 34 10

15
15

思路:过程的最后一步为前n门课总分为j的种类;

    最后一步的子问题为:前n-1门课总分为j-k的种类;

    显然;k>=p&&k<=j-p*(n-1);(保证每门课都能取到最低值);

    状态转移方程为:dp[i][j]+=dp[i-1][j-k];

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define PI 3.141592653589792128462643383279502
int dp[][];
int n;
int main(){
//#ifdef CDZSC_June
//freopen("in.txt","r",stdin);
//#endif
//std::ios::sync_with_stdio(false);
cin>>n;
int N,T,P;
while(n--){
cin>>N>>T>>P; memset(dp,,sizeof(dp));
for(int i=;i<=;i++)dp[][i]=;
for(int i=;i<=N;i++)
for(int j=P;j<=T;j++){
for(int k=P;k<=j-P*(i-);k++)
dp[i][j]+=dp[i-][j-k];
}
cout<<dp[N][T]<<endl;
}
return ;
}

uva 10910(子集和问题)的更多相关文章

  1. uva 10910

    简单dp /************************************************************************* > Author: xlc2845 ...

  2. UVA 10910 Marks Distribution

    题意 把数字T分成N个数的和,保证这N个数中最小的数大于P.求方案数目 另f[i][j]表示把i分成j个数的和的方案数 f[i][j]=f[i][j-1]+f[i-1][j-1]+f[i-2][j-1 ...

  3. uva 11825 Hackers&#39; Crackdown (状压dp,子集枚举)

    题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...

  4. UVa 11825 - Hackers' Crackdown DP, 枚举子集substa = (substa - 1)&sta 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  5. UVA 1508 - Equipment 状态压缩 枚举子集 dfs

    UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...

  6. UVA 11825 - Hackers&#39; Crackdown 状态压缩 dp 枚举子集

    UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...

  7. UVA 11825 Hackers’ Crackdown(集合动态规划 子集枚举)

    Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...

  8. Equipment UVA - 1508(子集补集)

    The Korea Defense and Science Institute, shortly KDSI, has been putting constant effort into newequi ...

  9. uva 11825 巧妙地子集枚举方法

    https://vjudge.net/problem/UVA-11825 题目大意,有n台服务器,有n种服务,每台服务器都运行着所有的服务,一台服务器可以被攻击一次其中的一种服务,当你选择攻击某台服务 ...

随机推荐

  1. truncate与delete以及drop

    truncate:删除整个表,但不删除定义(删除了整个表的数据,但表结构还在) drop:删除整个表,表数据和表结构都删除了 delete:删除表中数据 比较delete和drop 1.truncat ...

  2. Jmeter-6-创建数据库测试计划

    1. 将mysql 的jdbc的jar包放到Jmeter lib的目录下. 2. 创建线程组. 3. 创建JDBC Connection Configuration, 提供详细的数据库配置信息. 4. ...

  3. hdu 2157 How many ways?? ——矩阵十题第八题

    Problem Description 春天到了, HDU校园里开满了花, 姹紫嫣红, 非常美丽. 葱头是个爱花的人, 看着校花校草竞相开放, 漫步校园, 心情也变得舒畅. 为了多看看这迷人的校园, ...

  4. 【NOIP】提高组2013 转圈游戏

    [算法]快速幂运算 [题解]ans=(m*10^k+x)%n,用快速幂计算10^k即可,复杂度为O(log k). #include<cstdio> long long n,m,k,x,a ...

  5. 【STSRM10】dp只会看规律

    [算法]区间DP [题意]平面上有n个点(xi,yi),用最少个数的底边在x轴上且面积为S的矩形覆盖这些点(在边界上也算覆盖),n<=100. [题解]随机大数据下,贪心几乎没有错误,贪心出奇迹 ...

  6. hdu 1272 小希的迷宫(并查集+最小生成树+队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1272 小希的迷宫 Time Limit: 2000/1000 MS (Java/Others)     ...

  7. Perl6 Bailador框架(5):利用正则匹配路径

    use v6; use Bailador; =begin pod 我们在路径设置上, 可以利正则表达式捕获的字符串作为子例程参数 =end pod get '/perl6/(.+)' => su ...

  8. 利用keepalive+mysql replication 实现数据库的高可用

    利用keepalive+mysql replication 实现数据库的高可用 http://www.xuchanggang.cn/archives/866.html

  9. jQuery -《锋利的jQuery》————读后小结

    jQuery是一个优秀的javascript库. 我用的是vs2012自带的  jquery-1.8.2.js这个库,在Scripts这个文件夹下面 首先,我们使用jQuery要在head标签内引入j ...

  10. CDN网站加速技术

    什么是CDN? CDN(Content Delivery Network 内容分发网络)技术通过在各个地区部署缓存节点加速用户对静态资源的获取速度,提升用户体验,降低运营成本.CDN公司有网宿(Chi ...