hdu1028 Ignatius and the Princess III(生成函数整理占坑)

题解

生成函数处理整数拆分

code

#include<cstdio>    
#include<cstring>   
#include<algorithm>  
inline int raed() { 
    int x = 0,f = 1; 
    char c = getchar(); 
    while(c < '0' || c < '9') c = getchar(); 
    while(c <= '9' && c >= '0')x = x * 10 + c - '0',c = getchar(); 
    return x * f; 
} 
const int maxn = 564; 
int a[maxn],b[maxn]; 
int main() { 
    int n; 
    while(scanf("%d",&n) == 1) { 
        for(int i = 0;i <= n;++ i) 
            a[i] = 1,b[i] = 0;
        for(int i = 2;i <= n;++ i) {  
            for(int j = 0;j <= n;++ j) 
                for(int k = 0;k + j <= n;k += i) 
                    b[j + k] += a[j]; 
            for(int j = 0;j <= n;++ j) 
                a[j] = b[j],b[j] = 0; 
        } 
        printf("%d\n",a[n]); 
    }
    return 0; 
} 

猜你喜欢

转载自www.cnblogs.com/sssy/p/9064077.html