Project Euler:Problem 76 Counting summations
来源:互联网 发布:联通大数据宣传片 编辑:程序博客网 时间:2024/05/22 13:06
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;}elsefor (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");}
0 0
- Project Euler:Problem 76 Counting summations
- Project Euler:Problem 77 Prime summations
- Eularproject 76:Counting summations
- Project Euler:Problem 19 Counting Sundays
- Project Euler:Problem 72 Counting fractions
- Project Euler:Problem 85 Counting rectangles
- Project Euler Problem 19 Counting Sundays
- Project Euler:Problem 73 Counting fractions in a range
- Project Euler #77: Prime summations 回溯法得不到满分
- Project Euler Problem 76-整数分拆
- Euler Project Problem 6
- project euler problem 11
- Project Euler Problem 81
- Project Euler Problem 60
- Project Euler Problem 59
- Project Euler Problem 58
- Project Euler Problem 57
- Project Euler Problem 16
- java面试中注意的问题02
- 【Cocos2d-x】CCArray
- 第三方登录之微信登录
- Memcached入门一
- 【暑假】[ 图论 ] MST、最短路总结
- Project Euler:Problem 76 Counting summations
- android view构造函数研究
- <转>如何在CentOS 5/6上安装EPEL 源
- 求转子曲线所包围的封闭区域的面积
- android:How to delete a module in Android Studio?
- 计算机意外地重新启动或遇到错误。Windows 安装无法继续。若要安装Windows,请单击“确定”重新启动计算机,然后重新启动安装”。
- 邮件中的抄送和密送的区别
- VC 获取任务栏窗口的句柄
- 从头开始学习 Dojo,第 1 部分: 开始 Dojo 开发