Project Euler:Problem 76 Counting summations
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的更多相关文章
- 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 + ...
- Project Euler:Problem 55 Lychrel numbers
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- luogu P4115 Qtree4
题目链接 luogu P4115 Qtree4 题解 动态点分治,和上一题一样.同样三个堆.就是带权,用边权替换深度就好 为什么要单独写这个题解呢,因为我卡常卡了一天....据说树剖比rmq快? 在第 ...
- 51Nod1140 矩阵相乘的结果
随机化算法. A*B==C那么X*A*B==X*C 降到了n*n复杂度. 多次随机X判断即可. By:大奕哥 #include<bits/stdc++.h> using namespace ...
- 【静态主席树】POJ2104-K-th Number
求区间第k大.裸线段树. 莫队版本:☆ #include<iostream> #include<cstdio> #include<cstring> #include ...
- 安装myeclipse的常见问题
1.破解myeclipse网站: https://jingyan.baidu.com/article/acf728fd49519ff8e410a361.html
- linq to datatable 和lambda查询datatable
用Linq查询DataTable static DataTable table = new DataTable(); static DataColumn dc = new DataColumn(); ...
- April Fools Day Contest 2016 F. Ace It!
F. Ace It! 题目连接: http://www.codeforces.com/contest/656/problem/F Description Input The only line of ...
- Codeforces Round #302 (Div. 1) C. Remembering Strings DP
C. Remembering Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- RTL8188EUS带天线的WiFi模块
http://www.liuliutech.com/ProductShow.asp?ID=121 一,公司介绍瑞昱(REALTEK)半导体成立于1987年,位于台湾[硅谷]的新竹科学园区.凭借着7位创 ...
- .NET Transactional File Manager
.NET Transactional File Manager http://transactionalfilemgr.codeplex.com/ 对文件系统操作,比如copy, move, dele ...
- 【spring cloud】spring cloud 使用feign调用,1.fallback熔断器不起作用,2.启动报错Caused by: java.lang.ClassNotFoundException: com.netflix.hystrix.contrib.javanica.aop.aspectj.Hystri解决
示例GitHub源码地址:https://github.com/AngelSXD/springcloud 1.首先使用feign调用,需要配置熔断器 2.配置熔断器需要将熔断器注入Bean,熔断器类上 ...