Project Euler:problem Counting summations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.