codevs1137 计算系数

1137 计算系数

 

2011年NOIP全国联赛提高组

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 黄金 Gold
 
 
 
题目描述 Description

给定一个多项式(ax + by)^k,请求出多项式展开后x^n y^m项的系数。

输入描述 Input Description

共一行,包含 5 个整数,分别为a,b,k,n,m,每两个整数之间用一个空格隔开。

输出描述 Output Description

输出共 1 行,包含一个整数,表示所求的系数,这个系数可能很大,输出对10007 取模后的结果。

样例输入 Sample Input

1 1 3 1 2

样例输出 Sample Output

3

数据范围及提示 Data Size & Hint

数据范围
对于 30%的数据,有0≤k≤10;
对于 50%的数据,有a = 1,b = 1;
对于 100%的数据,有0≤k≤1,000,0≤n, m≤k,且n + m = k,0≤a,b≤1,000,000。

略水

#include<iostream>
#include<cstdio>
using namespace std;
int x[1001][2001];
int main()
{
    int a,b,k,n,m;
    scanf("%d%d%d%d%d",&a,&b,&k,&n,&m);
    a%=10007;b%=10007;
    x[1][1]=b;x[1][2]=a;
    for(int i=2;i<=k;i++)
      for(int j=1;j<=i+1;j++)
        x[i][j]=(x[i-1][j]*b+x[i-1][j-1]*a)%10007;
    cout<<x[k][n+1];
    return 0;
}
原文地址:https://www.cnblogs.com/xiaoningmeng/p/5906994.html