forked from wandering007/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP76.cpp
More file actions
57 lines (55 loc) · 1.26 KB
/
P76.cpp
File metadata and controls
57 lines (55 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
#include<fstream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iomanip>
#define MAXN 1500000
#define MOD 10000000000
#define LL long long
#define eps 1e-8
#define inf 0x3f3f3f3f
using namespace std;
//a slow way, 2s
int NumOfSum(int p, int x, int sum)
{
if(1 == x)
return 1;//x == 1时,系数唯一,取sum - p
int res = 0;
for(int i = 0; i + p <= sum; i += x)
res += NumOfSum(p + i, x - 1, sum);
return res;
}
int main()
{
clock_t start = clock();
printf("%d\n", NumOfSum(0, 99, 100));
printf("time cost: %lf s.", (double)(clock() - start) / CLOCKS_PER_SEC);
return 0;
}
//a fast way, 0s
/*
int sum[101];
int main()
{
clock_t start = clock();
sum[0] = 1;
for(int i = 1; i <= 99; i++)//i只能到99,保证至少有两个被加数
for(int j = i; j <= 100; j++)
sum[j] += sum[j - i];//和值为j、加数中最大值为i的种类数加到sum[j]中
printf("%d\n", sum[100]);
printf("time cost: %lf s.", (double)(clock() - start) / CLOCKS_PER_SEC);
return 0;
}
*/