hdu 1028 Ignatius and the Princess III(整数拆分较大数据量模板)

题目链接:

点击打开链接

题目大意:

拆分整数,仅排列顺序不同的情况算作一种,问最终一共有多少种情况

题目分析:

模板题

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX 127

using namespace std;

typedef long long LL;
LL p[MAX];

void perpare ( )
{
    LL i , j , k , s , o;
    p[0] = 1;
    for ( i = 1 ; i < MAX ; i++  )
    {
        j = 1 , k = 1 , s = 0 , o = -1;
        for ( ; j > 0 ; k++ , o *= -1 )
        {
            j = i - ( 3*k*k+k)/2;
            if ( j >= 0 )  s-= o * p[j];
            j = i - ( 3*k*k-k)/2;
            if ( j >= 0 ) s -= o* p[j];
        }
        p[i] = s;
    }
}

int main ( )
{
    perpare();
    /*for ( int i = 0 ; i <= 10 ; i++ )
        printf ( "%d " , p[i] );
    cout << endl;*/
    int n;
    while ( ~scanf ( "%d" , &n ))
    {
        printf ( "%I64d\n" , p[n] );
    }
}


你可能感兴趣的:(C++,整数拆分)