Codes/Volume 02/E0076 Counting summations.cpp
/*
Statement:
It is possible to write five as a sum in exactly six different ways:

4 + 1
3 + 2
3 + 1 + 1
2 + 2 + 1
2 + 1 + 1 + 1
1 + 1 + 1 + 1 + 1

How many different ways can one hundred be written as a sum of at least two positive integers?
*/
It is possible to write five as a sum in exactly six different ways.




It is possible to write five as a sum in exactly six different ways .
vector<ll> countPartitionTill(int bound){
    vector<ll> memo(bound+1);
    memo[0] = 1;
    for(int summand = 1; summand <= bound; summand++){
        for(int sum = summand; sum <= bound; sum++){
            memo[sum] += memo[sum-summand];
            if(memo[sum] < 0) assert(!"Overflow");
        }
    }
    return memo;
}
vector < ll > countPartitionTill ( int bound ) { vector < ll > memo ( bound + 1 ) ; memo [ 0 ] = 1 ; for ( int summand = 1 ; summand <= bound ; summand ++ ) { for ( int sum = summand ; sum <= bound ; sum ++ ) { memo [ sum ] += memo [ sum - summand ] ; if ( memo [ sum ] < 0 ) assert ( ! " " ) ; } } return memo ; }
Statement:
It is possible to write five as a sum in exactly six different ways:
Statement : It is possible to write five as a sum in exactly six different ways :