24h購物| | PChome| 登入
2012-05-17 19:01:40| 人氣677| 回應0 | 上一篇 | 下一篇

[UVA][組何分配] 10910 - Marks Distribution

推薦 0 收藏 0 轉貼0 訂閱站台

4th IIUC Inter-University Programming Contest, 2005

F

Marks Distribution

Input: standard input
Output: standard output

Problemsetter: Md. Bahlul Haider
Judge Solution: Tanveer Ahsan

In an examination one student appeared in N subjects and has got total T marks. He has passed in all the N subjects 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
3 34 10
3 34 10

15
15



多出來的分數p, 分給 n 個箱

#include <stdio.h>

int main() {
    int pascal[100][100] = {};
    int i, j;
    pascal[0][0] = 1;
    for(i = 1; i < 100; i++) {
        pascal[i][0] = 1;
        for(j = 1; j <= i; j++) {
            pascal[i][j] = pascal[i-1][j]+pascal[i-1][j-1];
        }
    }
    int tt, n, t, p;
    scanf("%d", &tt);
    while(tt--) {
        scanf("%d %d %d", &n, &t, &p);
        if(t < n*p)
            puts("0");
        else
            printf("%d\n", pascal[t-n*p+n-1][n-1]);
    }
    return 0;
}

台長: Morris
人氣(677) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 11417 - GCD
此分類上一篇:[UVA] 11703 - sqrt log sin

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文