2786: Ural1142 Relation (递推+高精度)

用=号连接的元素看做一个集合,忽略顺序;

定义f[i][j] 为前i个元素分成j组的方案数;

第i个元素

1、新建一个集合 由 f[i-1][j-1]*j;

2、归入原有集合 由 f[i-1][j]*j;


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
struct Q {
	int l, s[100];
	Q () { l = 1; memset (s, 0, sizeof s); }
}f[51][51], s[51], a, b;
inline Q operator + (const Q & a, const Q & b)
{
	Q c;
	c.l = max (a.l, b.l);
	for (int i = 1; i <= c.l; i ++)
	{
		c.s[i] += a.s[i] + b.s[i];
		c.s[i + 1] += c.s[i] / 10;
		c.s[i] %= 10;
	}
	if (c.s[c.l + 1]) c.l ++;
	return c;
}
inline Q operator * (const Q & a, int b)
{
	Q c;
	c.l = a.l;
	for (int i = 1; i <= a.l; i ++)
	{
		c.s[i] += a.s[i] * b;
		c.s[i + 1] += c.s[i] / 10;
		c.s[i] %= 10;
	}
	while (c.s[c.l + 1]) c.l ++;
	return c;
}
inline void print (const Q & a)
{
	for (int i = a.l; i >= 1; i --)
		printf ("%d", a.s[i]);puts ("");
}
int main ()
{

	int T;
	scanf ("%d", &T);
	s[1].s[1] = f[1][1].s[1] = 1;
	for (int i = 2; i <= 50; i ++)
		for (int j = 1; j <= i; j ++)
			s[i] = s[i] + (f[i][j] = f[i - 1][j] * j + f[i - 1][j - 1] * j);
	while (T --)
	{
		int n;
		scanf ("%d", &n);
		print (s[n]);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值