Description
求 n n 的本质不同拆分数
Input
多组用例,每组用例输入一整数
Output
对于每组用例,输出 n n 的本质不同拆分数
Sample Input
4
10
20
Sample Output
5
42
627
Solution
设的拆分数为 p(n) p ( n ) ,由五边形数定理有 p(n)=p(n−1)+p(n−2)−p(n−5)−p(n−7)+... p ( n ) = p ( n − 1 ) + p ( n − 2 ) − p ( n − 5 ) − p ( n − 7 ) + . . .
O(nn−−√) O ( n n ) 即可筛出 p(1) p ( 1 ) ~ p(n) p ( n )
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=123;
int n,f[maxn];
int main()
{
for(int i=1;i<=120;i++)f[i]=0;
f[0]=1;
for(int i=1;i<=120;i++)
{
for(int j=1,w=1;w<=i;w+=3*j+1,j++)
if(j&1)f[i]+=f[i-w];
else f[i]-=f[i-w];
for(int j=1,w=2;w<=i;w+=3*j+2,j++)
if(j&1)f[i]+=f[i-w];
else f[i]-=f[i-w];
}
while(~scanf("%d",&n))printf("%d\n",f[n]);
return 0;
}