首页 > 代码库 > UVA 10910 Marks Distribution

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]+...f[0][j-1];

f[i-1][j]=f[i-1][j-1]+f[i-2][j-1]+...f[0][j-1];

两式做差 推出f[i][j]=f[i-1][j]+f[i][j-1];

那么ans=f[T-NP][N];

#include <map>#include <set>#include <list>#include <cmath>#include <ctime>#include <deque>#include <stack>#include <queue>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <climits>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define PI 3.1415926535897932626using namespace std;int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}#define MAXN 500LL f[MAXN][MAXN];int N,T,P;void init(){    for (int i=0;i<MAXN;i++) for (int j=0;j<MAXN;j++) f[i][j]=0;    for (int i=1;i<=200;i++)        f[0][i]=1;    for (int i=1;i<=200;i++)        for (int j=1;j<=200;j++)        f[i][j]=f[i-1][j]+f[i][j-1];}int main(){    init();    int kase;    scanf("%d",&kase);    while (kase--)    {        scanf("%d%d%d",&N,&T,&P);        if (T-N*P<0) {puts("0");continue;}        else printf("%lld\n",f[T-N*P][N]);    }    return 0;}

 

UVA 10910 Marks Distribution