csuoj2310 count-partitions(Ferrer图像)

csuoj2310 count-partitions(Ferrer图像)

题目大意

给出n个方格,问能组成多少种共轭Ferrer图像

解题思路

任何的共轭Ferrer图像都可以看作一个正方形加上两个普通的高度小于正方形边长的Ferrer图像,而小于某一高度的Ferrer图像可以通过递推得到,设由i个方格组成高度小于h的Ferrer图像有 d p [ i ] [ h ] dp[i][h] dp[i][h]

那么就有递推关系式
d p [ i ] [ h ] = d p [ i ] [ h − 1 ] + d p [ i − h ] [ h ] dp[i][h]=dp[i][h-1]+dp[i-h][h] dp[i][h]=dp[i][h1]+dp[ih][h]

AC代码

#include<bits/stdc++.h>
using namespace std;
const int size=2e5+5;
const int mod=998244353;
const int h=sqrt(size)+1;
int dp[size][h];
int ans[size];
void init()
{
	memset(dp,0,sizeof(dp));
	memset(ans,0,sizeof(ans));
	dp[0][0]=1;
	for(int i=0;i<size;i++)
	{
		for(int j=1;j<h;j++)
		{
			dp[i][j]=dp[i][j-1];
			if(i>=j)
				dp[i][j]=(dp[i-j][j]+dp[i][j])%mod;
		}
	}
	for(int i=1;i<size;i++)
	{
		for(int j=1;j*j<=i;j++)
		{
			int last=i-j*j; 
			if(last%2==0)
			{
				ans[i]=(ans[i]+dp[last/2][j])%mod;
			}
		}
	}
}
int main()
{	
	init();
	int n;
	int t;
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d",&n);
		printf("%d\n",ans[n]);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值