It is possible-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 is written as a sum of at least b positive integers?
#include <iostream>using namespace Std;int c = 0;//tired divide number void p (int n, int a[], int m)//m represents the number of addend for each partition {int i;if (n = = 0) {C++;//int i;//for (i = 0; i < m-1; i++)//cout << a[i] << "+";//cout << a[m-1] << Endl;} Elsefor (i = n; I >= 1; i--) {if (M = = 0 | | I <= a[m-1])//To ensure that the next partitioning factor is not greater than the previous partition factor {a[m] = I;p (N-i, A, M + 1);}} void Main (void) {int N;int a[200] = {0};//stores the division of Integer n printf ("Input integer to be divided:"); Cin >> N;p (n, a, 0); cout << "Integer" < < n << "is divided into:" << c-1 << "species. "<< Endl;system (" pause ");}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Project Euler:problem Counting summations