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. iOS开发者两分钟学会用GitHub在Mac上托管代码的两种方法

        原文发布者:http://blog.csdn.net/duxinfeng2010 在Mac上使用Xcode进行iOS-Apple苹果iPhone手机开发过程中少不了使用GitHub在Mac上托 ...

  2. linux 下用 c 实现 ls -l 命令

    #include <stdio.h> #include <sys/types.h> #include <dirent.h> #include <sys/sta ...

  3. MSSQL数据库 事务隔离级别

    数据库事务的隔离级别有4个,由低到高依次为Read uncommitted .Read committed .Repeatable read .Serializable ,这四个级别可以逐个解 脏读 ...

  4. 总有你要的编程书单(GitHub )

    目录 IDE IntelliJ IDEA 简体中文专题教程 MySQL 21分钟MySQL入门教程 MySQL索引背后的数据结构及算法原理 NoSQL Disque 使用教程 Neo4j .rb 中文 ...

  5. 新建一个express工程,node app无反应

    1.问题描述 新建一个express工程,node app以后无反应,浏览器输入localhost:3000,显示如下 2.解决方法 在app.js文件中加入如下代码 app.listen(3000, ...

  6. python进行机器学习(三)之模型选择与构建

    Scikit-Learn库已经实现了所有基本机器学习的算法,可以直接调用里面库进行模型构建. 一.逻辑回归 大多数情况下被用来解决分类问题(二元分类),但多类的分类(所谓的一对多方法)也适用.这个算法 ...

  7. 需要重刷整個 image 的時機 - 1

    最近遇到一個問題, gpio 讀出來的值與預期不同, 詳細描述如下: 首先手機 download 了一個完整的 daily build image , 接下來 不斷地修改 kernel 部分 code ...

  8. centos_7.1.1503_src_3

    http://vault.centos.org/7.1.1503/os/Source/SPackages/ kdf-4.10.5-3.el7.src.rpm 05-Jul-2014 13:28 161 ...

  9. 使用cURL POST上传文件

    使用cURL POST上传文件 http://blog.csdn.net/v6543210/article/details/20152575

  10. [hadoop][会装]zookeeper安装

    1.简介 分布式场景下的各个进程间的协调运作离不开zookeeper, zookeeper已经是大数据领域提供分布式协调服务的事实标准. 本文只介绍zookeeper的安装方法. 2. 节点规划如下: ...