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 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.
这里写图片描述
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 1 ≤ N ≤ 70, 1 ≤ P ≤ T ≤ 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
2
3 34 10
3 34 10
Sample Output
15
15

中文:
给你三个数n,t,p分别表示科目总数,你需要获得的总分数n个学科当中你最少要得到的分数。现在问你有多少中得分方法?

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll CC(ll n,ll k)
{
    if(n-k<k)
        k=n-k;
    ll ans=1;
    for(int i=1;i<=k;i++)
        ans=ans*(n-i+1)/i;
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    ll n,p,t;
    int m;
    cin>>m;
    while(m--)
    {
        cin>>n>>t>>p;
        t-=n*p;
        cout<<CC(t+n-1,n-1)<<endl;
    }
    return 0;
}

解答:
首先把总分数减去科目数乘以最低分数,然后把剩下的分数分给这几个科目,有多少种分法?相当于是用n个无区别的小球放进m个有区别的盒子里。C(n+m-1,m)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值