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. Tomcat+Apache集群方案

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha # environment slash for Windows(反斜杠代表Windows ...

  2. UVA11107 Life Forms --- 后缀数组

    UVA11107 Life Forms 题目描述: 求出出现在一半以上的字符串内的最长字符串. 数据范围: \(\sum len(string) <= 10^{5}\) 非常坑的题目. 思路非常 ...

  3. Nginx 502 Bad Gateway 解决方法

    proxy_next_upstream error timeout invalid_header http_500 http_503;或者尝试设置:large_client_header_buffer ...

  4. Java解释执行和编译执行

    以前有句话说:“Java是解释执行的 ” .现在看来确实不是很准确,至于原因,在此简略解释: 首先,我们先解释一下在Java中解释执行和编译执行的区别. 解释执行:将编译好的字节码一行一行地翻译为机器 ...

  5. 24.最优布线问题(kruskal算法)

    时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 Description 学校需要将n台计算机连接起来,不同的2台计算机之间的连接费用 ...

  6. Java高级架构师(一)第40节:更多模块的基本功能和配置

  7. hdu 1540 Tunnel Warfare 线段树 单点更新,查询区间长度,区间合并

    Tunnel Warfare Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. PAT甲级1003. Emergency

    PAT甲级1003. Emergency 题意: 作为一个城市的紧急救援队长,你将得到一个你所在国家的特别地图.该地图显示了几条分散的城市,连接着一些道路.每个城市的救援队数量和任何一对城市之间的每条 ...

  9. FLV视频在IIS6.0下不能播放 处理的方法

    FLV视频在IIS6.0下不能播放 Flash视频由于其较高的压缩率和优越的下载速度,前景普遍看好,同时也为Flash课件增色不少.然而,在FLV视频播放中,却有两个头痛的问题    一.FLV视频在 ...

  10. java常用工具方法2

    /* * Copyright 2005 Joe Walker * * Licensed under the Apache License, Version 2.0 (the "License ...