• Loading...

Problem 5: Partitions

Points:

Small Case: 10 Answer: 23

Large Case: 20 Answer: 81198940

For any number N, a special partition S= { a1,a2,a3,...... ap } with respect to a given integer 'R', is defined as

1- ai >0 for 1<=i<=p
2- ai+1 >=ai
3- a1+a2+a3+.....ap = N
4- Every number 'm' such that 1<=m<= R*N can be expressed as

m= SIGMA ( ai* xi ) ) for 1<=i<=p

where xi belongs to X= {-R,-R+1, ...,-1, 0,1 ,.... ,R-1,R }

For e.g. if N = 3, R = 2 and K = 2,
X = {-2, -1, 0, 1, 2}
There are only two such possible partitions: {1,2} and {1,1,1}.


1 = 1 * 1 + 0 * 2 = 1 * 1 + 0 * 1 + 0 * 1
2 = 0 * 1 + 1 * 2 = 1 * 1 + 1 * 1 + 0 * 1
3 = 1 * 1 + 1 * 2 = 1 * 1 + 1 * 1 + 1 * 1
4 = 2 * 1 + 1 * 2 = 2 * 1 + 1 * 1 + 1 * 1
5 = 1 * 1 + 2 * 2 = 2 * 1 + 2 * 1 + 1 * 1
6 = 2 * 1 + 2 * 2 = 2 * 1 + 2 * 1 + 2 * 1

Hence, the total number of such partitions is 2.

Given the maximum value 'K' that ap can attain and the value of 'R',
find the total number of these special partitions on N modulo 100000007.

Small Case:N=10 ,R=2 ,K=5
Large Case:N=1000 ,R=15 ,K=1000

Solution:

Let Sr,k(n) be the number of r-subcomplete partitions of n whose largest part is at most k. Then Sr,1(n) = 1 for all n and for k >= 2
Reload Page
with initial conditions Sr,1(0) = 1 and Sr,0(n) = 0 for all n.

Reference:HoKyu Lee and SeungKyung Park,The r-subcomplete Partitions,2002,Theorem 2.13

Code:


#include <iostream>
#include <cassert>
using namespace std;
const int MOD=100000007;
int S[1001][1001];
int main()
{

    int r=15,k=1000,n=1000;
    int ans=0;

    for(int i=0;i<=k;++i)
        for(int j=0;j<=n;++j)
            S[i][j]=0;

    for ( int i=0;i<=n;++i)
        S[1][i]=1;

    for ( int i=2;i<=k;++i)
        for ( int j=1;j<=n;++j){
            int val=(2*r*j+1)/(2*r+1);
            if ( i > val )
                S[i][j]=S[val][j];
            else
                S[i][j]=(S[i-1][j]+S[i][j-i])%MOD;

        }
    cout<<S[k][n];
return 0;
}

Submit your solution

You need to be logged in to submit a solution.

discussions


There is no discussion yet. Feel free to ask an question you might have regarding this problem


post a question

Loading...

Problem 1
Problem 2
Problem 3
Problem 4
Problem 5 (bonus) Expired
Problem 1
Problem 2
Problem 3
Problem 4 (bonus) Expired
Top Scorers
rng_58 235
Anton_Lunyov 225
tourist 190
Silence 180
cedricl2 175
cgy4ever 175
DrKorbin 165
Koen 155
bbbasic 150
lunae_2 150
Submissions
Problem 1
10 pt
not submitted
98
submissions

19
correct (19 %)



25 pt
not submitted
2
submissions

1
correct (50 %)


Problem 2
5 pt
not submitted
95
submissions

38
correct (40 %)



10 pt
not submitted
19
submissions

15
correct (78 %)


Problem 3
5 pt
not submitted
153
submissions

117
correct (76 %)



15 pt
not submitted
44
submissions

25
correct (56 %)


Problem 4
10 pt
not submitted
152
submissions

54
correct (35 %)



15 pt
not submitted
23
submissions

10
correct (43 %)


Problem 5
10 pt
not submitted
36
submissions

28
correct (77 %)



20 pt
not submitted
6
submissions

2
correct (33 %)


Problem 6
5 pt
not submitted
41
submissions

29
correct (70 %)



10 pt
not submitted
15
submissions

14
correct (93 %)


Problem 7
5 pt
not submitted
38
submissions

17
correct (44 %)



10 pt
not submitted
16
submissions

15
correct (93 %)


Problem 8
5 pt
not submitted
127
submissions

104
correct (81 %)



15 pt
not submitted
47
submissions

34
correct (72 %)


Problem 9
5 pt
not submitted
86
submissions

35
correct (40 %)



15 pt
not submitted
16
submissions

15
correct (93 %)


Problem 10
5 pt
not submitted
45
submissions

23
correct (51 %)



15 pt
not submitted
15
submissions

14
correct (93 %)


Problem 11
5 pt
not submitted
81
submissions

27
correct (33 %)



15 pt
not submitted
8
submissions

3
correct (37 %)


Problem 12
5 pt
not submitted
104
submissions

88
correct (84 %)



10 pt
not submitted
31
submissions

21
correct (67 %)