UVA 10910 - Marks Distribution (dp)
2013-11-13 21:14
330 查看
4th IIUC Inter-University Programming Contest, 2005 | |
F | Marks Distribution |
Input: standard input Output: standard output | |
Problemsetter: Md. Bahlul Haider Judge Solution: Tanveer Ahsan |
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 andP=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 |
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 3 34 10 3 34 10 | 15 15 |
思路:dp。i表示第i个人,j表示总和为j。状态转移方程为f[i][j] += f[i - 1][j - k];
代码:
#include <stdio.h>
#include <string.h>
int T, n, t, p, f[75][75];
int main() {
scanf("%d", &T);
while (T --) {
scanf("%d%d%d", &n, &t, &p);
int num = t - n * p;
for (int i = 0; i <= num; i ++)
f[1][i] = 1;
for (int i = 2; i <= n; i ++) {
for (int j = 0; j <= num; j ++) {
f[i][j] = 0;
for (int k = 0; k <= j; k ++) {
f[i][j] += f[i - 1][j - k];
}
}
}
printf("%d\n", f
[num]);
}
return 0;
}
相关文章推荐
- uva 10910 - Marks Distribution(dp)
- (Relax DP1.2)UVA 10910 Marks Distribution(求通过n门课获得t分的情况数,每门课至少能获得p分)
- UVA - 10910 Marks Distribution 简单DP
- UVA10910 Marks Distribution【组合+DP】
- UVA10910 - Marks Distribution(dp)
- uva 10917 Walk Through the Forest(最短路+DP路径,4级)
- Caves - UVa 1407 树形dp
- UVA 116 Unidirectional TSP——dp
- UVA 1619 - Feel Good(dp 求区间最小值 附加RMQ)(区间最小值优化)
- UVA 11468 Substring(AC自动机+概率DP)
- uva10306(dp)
- UVA12283 Halloween Costumes(区间dp)
- UVa 12525 Boxes and Stones (dp 博弈)
- UVA 1252 Twenty Questions 状压DP
- UVA 11795 Mega Man's Mission(状态压缩DP)
- UVa 10154 Weights and Measures DP
- Uva 10559 & POJ 1390 Blocks 区间dp
- UVA - 1543(dp)
- uva 437 The Tower of Babylon(DAG的DP)
- uva 12093 Protecting Zonk 树形dp