UVa 10105 Polynomial Coefficients(组合数学)

262 篇文章 0 订阅
49 篇文章 0 订阅

10105 - Polynomial Coefficients

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1046

The Problem

The problem is to calculate the coefficients in expansion of polynomial(x1+x2+...+xk)n.

The Input

The input will consist of a set of pairs of lines. The first line of the pair consists of two integers n and k separated with space (0<K,N<13). This integers define the power of the polynomial and the amount of the variables. The second line in each pair consists of k non-negative integers n1, ..., nk, where n1+...+nk=n.

The Output

For each input pair of lines the output line should consist one integer, the coefficient by the monomial x1n1x2n2...xknk in expansion of the polynomial(x1+x2+...+xk)n.

Sample Input

2 2
1 1
2 12
1 0 0 0 0 0 0 0 0 0 1 0

Sample Output

2
2

题意&思路:参考Richard A.Brualdi的《组合数学(第5版)》P88 (5.4 多项式定理)


完整代码:

非打表:

/*0.016s*/

#include <cstdio>
using namespace std;

int main()
{
	int n, k, ni;
	while (~scanf("%d%d", &n, &k))
	{
		long long sum = 1;
		for (int i = 2; i <= n; i++)
			sum *= i;
		while (k--)
		{
			scanf("%d", &ni);
			for (int i = 2; i <= ni; i++)
				sum /= i;
		}
		printf("%lld\n", sum);
	}
	return 0;
}

打表:

/*0.015s*/

#include <cstdio>
using namespace std;
const long long f[11] = {6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800};

int main()
{
	int n, k, ni;
	while (~scanf("%d%d", &n, &k))
	{
		long long sum = 1;
		if (n == 2)
			sum <<= 1;
		else if (n > 2)
			sum *= f[n - 3];
		while (k--)
		{
			scanf("%d", &ni);
			if (ni == 2)
				sum >>= 1;
			else if (ni > 2)
				sum /= f[ni - 3];
		}
		printf("%lld\n", sum);
	}
	return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值