uva 10910(子集和问题)
Marks Distribution
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=3, T=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 N, T and P respectively. The values of N, T 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 |
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(子集和问题)的更多相关文章
- uva 10910
简单dp /************************************************************************* > Author: xlc2845 ...
- 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 ...
- uva 11825 Hackers' Crackdown (状压dp,子集枚举)
题目链接:uva 11825 题意: 你是一个黑客,侵入了n台计算机(每台计算机有同样的n种服务),对每台计算机,你能够选择终止一项服务,则他与其相邻的这项服务都终止.你的目标是让很多其它的服务瘫痪( ...
- 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 ...
- UVA 1508 - Equipment 状态压缩 枚举子集 dfs
UVA 1508 - Equipment 状态压缩 枚举子集 dfs ACM 题目地址:option=com_onlinejudge&Itemid=8&category=457& ...
- UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集
UVA 11825 - Hackers' Crackdown 状态压缩 dp 枚举子集 ACM 题目地址:option=com_onlinejudge&Itemid=8&page=sh ...
- UVA 11825 Hackers’ Crackdown(集合动态规划 子集枚举)
Hackers’ Crackdown Miracle Corporations has a number of system services running in a distributed com ...
- Equipment UVA - 1508(子集补集)
The Korea Defense and Science Institute, shortly KDSI, has been putting constant effort into newequi ...
- uva 11825 巧妙地子集枚举方法
https://vjudge.net/problem/UVA-11825 题目大意,有n台服务器,有n种服务,每台服务器都运行着所有的服务,一台服务器可以被攻击一次其中的一种服务,当你选择攻击某台服务 ...
随机推荐
- Parallel
介绍 C# 4.0 的新特性之并行运算 Parallel.For - for 循环的并行运算 Parallel.ForEach - foreach 循环的并行运算 Parallel.Invoke - ...
- Jmeter 重要测试指标释义
Aggregate Report 是 JMeter 常用的一个 Listener,中文被翻译为“聚合报告”.今天再次有同行问到这个报告中的各项数据表示什么意思,顺便在这里公布一下,以备大家查阅. 如果 ...
- Android Studio键盘快捷键
Android Studio 为许多常用操作提供了键盘快捷键. 表 1 按操作系统显示了默认键盘快捷键. 注:除了下面表 1 中的默认键映射外,您还可以选择多种预设的键映射,也可以创建自定义键映射.如 ...
- 暑假集训——cf热身赛部分题有感加其题解
刚刚开始集训,集训队队长暂时还没有拉专题,而是拉了部分codeforces上过题人数在2000左右的题组成了一场热身赛(其实就是一场练习),花了一天时间终于把它刷完了,其中很多题让我学到了很多骚操作, ...
- CSS3禁止网页中文本被选中代码
通常大家会有js来实现,另一个方案就是,将-webkit-user-select 和-moz-user-select 的值设为none,这针对于移动用户,可能会很有用.请谨慎使用这个属性:因为大部分用 ...
- C++之参数总结
函数的形参为函数提供了已命名的局部存储空间,它是在函数的形参表中定义的,并由调用函数时传递给函数的实参初始化,而形参的 初始化与变量的初始化一样,如果形参具有非引用类型,则复制实参的值,如果形参为引用 ...
- Linux System.map文件【转】
转自:http://blog.csdn.net/ysbj123/article/details/51233618 当运行GNU链接器gld(ld)时若使用了"-M"选项,或者使用n ...
- (二十)ubuntu的recovery mode解决用户一些实际问题
遇到的问题如下: 1.在当前用户下使用sudo来直接修改password等几个文件,一旦修改了passwd,用户名发生了变化,其他的用户组.密码等却没有对应的配置,就再进不了该用户了. 2.忘记用户密 ...
- 封装构造函数,用canvas写饼状图和柱状图
封装构造函数,用canvas写饼状图和柱状图 封装函数 // 场景 function XDLScence( options ) { this.stage = options.stage; //执行场景 ...
- rabbitmq和ons-rocketmq使用对比
MQ,其实目的都是一样,就是应对系统的并发可以实现消峰和解耦的作用,类似于创建了一个线程异步操作,这一点可以了解一下一款优秀的并发框架(Disruptor),据说是每秒可以处理十万级数据, 目前据本人 ...