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?

#include <iostream>
using namespace std; int c = 0;//累划分数
void p(int n, int a[], int m)//m表示每一种划分的加数的个数
{
int i;
if (n == 0)
{
c++;
//int i;
//for (i = 0; i < m - 1; i++)
// cout << a[i] << "+";
//cout << a[m - 1] << endl;
}
else
for (i = n; i >= 1; i--)
{
if (m == 0 || i <= a[m - 1])//要保证下一个划分因子不大于上一个划分因子
{
a[m] = i;
p(n - i, a, m + 1);
}
}
} void main(void)
{
int n;
int a[200] = { 0 };//存储整数n的划分
printf("输入要被划分的整数: ");
cin >> n;
p(n, a, 0);
cout << "整数" << n << "的划分数是:" << c-1 << "种。" << endl;
system("pause");
}

Project Euler:Problem 76 Counting summations的更多相关文章

  1. Project Euler:Problem 77 Prime summations

    It is possible to write ten as the sum of primes in exactly five different ways: 7 + 3 5 + 5 5 + 3 + ...

  2. Project Euler:Problem 55 Lychrel numbers

    If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...

  3. Project Euler:Problem 63 Powerful digit counts

    The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is ...

  4. Project Euler:Problem 86 Cuboid route

    A spider, S, sits in one corner of a cuboid room, measuring 6 by 5 by 3, and a fly, F, sits in the o ...

  5. Project Euler:Problem 87 Prime power triples

    The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is ...

  6. Project Euler:Problem 89 Roman numerals

    For a number written in Roman numerals to be considered valid there are basic rules which must be fo ...

  7. Project Euler:Problem 93 Arithmetic expressions

    By using each of the digits from the set, {1, 2, 3, 4}, exactly once, and making use of the four ari ...

  8. Project Euler:Problem 39 Integer right triangles

    If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exact ...

  9. Project Euler:Problem 28 Number spiral diagonals

    Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is forme ...

随机推荐

  1. 【BZOJ 2306】 2306: [Ctsc2011]幸福路径 (倍增floyd)

    2306: [Ctsc2011]幸福路径 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 912  Solved: 437 Description 有向 ...

  2. ACM -- 算法小结(三)反转句子顺序与反转单词组成顺序

    hdoj 1321 反转句子字母顺序 ac 2011/10/05 #include <iostream> #include <string> #include <algo ...

  3. 发现一个可以搜索常用rpm包的地址(http://www.rpmfind.net/)

    http://www.rpmfind.net/ 虽然资源不多,但也够用.

  4. 原来通过修改dns加快app store下载速度的确有效

    说来惭愧,这几天休假,并没有做什么技术上的修行.小伙伴推荐我一款avg游戏<11eyes 罪与罚与被诅咒的少女>,说是神作.但是app store上卖rmb118元,起初并没有什么兴趣去购 ...

  5. 如何更新phpStorm SVN项目地址

    公司内网服务器换了IP地址,导致phpStorm 中的SVN更新不上去 如何在phpStorm中配置SVN这里就不赘述了,网上很多,自行百度 这里说一下如何更改phpStorm 中SVN地址 找到项目 ...

  6. Restrict form resize -- Delphi

    http://www.delphipages.com/forum/showthread.php?t=58391 Hi, How would I restrict a form from being r ...

  7. 修改gnome-shell扩展“Applications Menu”的菜单区域宽度。

    sudo打开 /usr/share/gnome-shell/extensions/apps-menu@gnome-shell-extensions.gcampax.github.com/extensi ...

  8. switch语句的基本使用

    switch是一个多分支的选择语句. 1.基本格式: switch(整型表达式){              case  整型字面量: ...... default  : } 解释: 1)整型字面量可 ...

  9. Eclipse搭建Gradle环境

    转自:http://blog.sina.com.cn/s/blog_4b20ae2e0102uz4t.html 1.上Grandle官网下载Gradle,地址:http://www.gradle.or ...

  10. Go -- 调用dll库

    package main import ( "syscall" "unsafe" ) func main(){ h, err := syscall.LoadLi ...