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 2728】 2728: [HNOI2012]与非 (线性基?)

    2728: [HNOI2012]与非 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 813  Solved: 389 Description Inpu ...

  2. 【BZOJ 3229】 3229: [Sdoi2008]石子合并 (GarsiaWachs算法)

    3229: [Sdoi2008]石子合并 Description 在一个操场上摆放着一排N堆石子.现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆石子合并成新的一堆,并将新的一堆石子数记为该次合 ...

  3. 【BZOJ 1016】 1016: [JSOI2008]最小生成树计数 (DFS|矩阵树定理)

    1016: [JSOI2008]最小生成树计数 Description 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的最小生成树.(如果两颗最小生成树 ...

  4. 2017-2018-1 JAVA实验站 冲刺 day04

    2017-2018-1 JAVA实验站 冲刺 day04 各个成员今日完成的任务 小组成员 今日工作 完成进度 张韵琪 写博客.进行工作总结 100% 齐力锋 找背景音乐 100% 张浩林 游戏操作说 ...

  5. bzoj 1458: 士兵占领 -- 最大流

    1458: 士兵占领 Time Limit: 10 Sec  Memory Limit: 64 MB Description 有一个M * N的棋盘,有的格子是障碍.现在你要选择一些格子来放置一些士兵 ...

  6. tarjan算法--cojs 1298. 通讯问题

    cojs 1298. 通讯问题 ★   输入文件:jdltt.in   输出文件:jdltt.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 一个篮球队有n个篮球队员, ...

  7. 小识.htaccess文件

    .htaccess文件(或者"分布式配置文件")提供了针对目录改变配置的方法, 即,在一个特定的文档目录中放置一个包含一个或多个指令的文件, 以作用于此目录及其所有子目录.作为用户 ...

  8. python开发_linecache

    #从linecache的名称,我们可以知道该模块和cache(缓存)有关 #linecache现把文件读入到缓存中,在以后访问文件的时候,就不必要再从硬盘读取 #所以经常用于那些读取频率很高的文件还可 ...

  9. 2015 UESTC 搜索专题F题 Eight Puzzle 爆搜

    Eight Puzzle Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 ...

  10. C#如何用OpenFileDialog控件打开图片显示到PictureBox这个控件

    openFileDialog1.Filter = "图片文件|*.jpg|BMP图片|*.bmp|Gif图片|*.gif"; OpenFileDialog ofd = new Op ...