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 4663】 (最小割)

    4663: Hack Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 69  Solved: 26 Description 由于 FZYZ 教学区禁止使 ...

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

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

  3. bzoj 2342: [Shoi2011]双倍回文 -- manacher

    2342: [Shoi2011]双倍回文 Time Limit: 10 Sec  Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符 ...

  4. iOS Core Animation 动画 入门学习(一)基础

    reference:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide ...

  5. Kafka 0.7.2 单机环境搭建

    Kafka 0.7.2 单机环境搭建当下载完Kafka后,进行解压,其目录结构如下: bin config contrib core DISCLAIMER examples lib lib_manag ...

  6. 普通免费QQ客服在PC、手机端解决方案

    注意:以下测试 浏览器在Chrome,手机在iphone6 营销QQ.企业QQ(http://b.qq.com/)跟普通免费QQ(http://shang.qq.com/v3/widget.html) ...

  7. ext:grid分页,列宽度自动填满grid宽度

    var cm = new Ext.grid.ColumnModel([{      header : '编号',      dataIndex : 'id'     }, {      header ...

  8. Raspberry pi,一个好玩的派:第八季 Raspbmc(下)

    上一季安装好Raspbmc就等着这一季好好玩耍呢. 我们要在这一季中完毕例如以下任务:调整分辨率.连接wifi并在无线路由器中设置固定IP.手机遥控Raspbmc.改变语言为中文.远程訪问Raspbe ...

  9. UnsupportedOperationException:can&#39;t convert to dimension :typx=0x1

    at android.content.res.TypeArray.getDimensionPixelSize(TypeArray.java:463) 今天在给项目做适配执行项目时遇到这个错误,发生错误 ...

  10. Unity3D协程介绍 以及 使用

    作者ChevyRay ,2013年9月28日,snaker7译  原文地址:http://unitypatterns.com/introduction-to-coroutines/ 在Unity中,协 ...