-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathDSA02028 - CHIA ĐỀU
68 lines (68 loc) · 2.22 KB
/
DSA02028 - CHIA ĐỀU
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
58
59
60
61
62
63
64
65
66
67
68
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
int n, k, d;
int a[15];
int solve(int u, int t)
{
if (t > k)
return 0;
if (u == n + 1)
{
if (t == k)
return 1;
return 0;
}
int sum = 0, ans = 0;
for (int i = u; i <= n; i++)
{
sum += a[i];
if (sum == d)
ans += solve(i + 1, t + 1);
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
d += a[i];
if (d % k != 0)
cout << 0;
else
{
d /= k;
cout << solve(1, 0);
}
}
/* Do Xuan Huong
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@
@@@@@@@@@@@@&####################################@@@@@@@@@@@@
@@@@@@@@@@##########################################@@@@@@@@@
@@@@@@@@##############################################@@@@@@@
@@@@@@#################################################@@@@@@
@@@@@####################################################@@@@
@@@%#####################@@@@@@@@@@@######################@@@
@@@###################@@@@@@@@@@@@@@@@@####################@@
@@##################@@@@@@ @@@@@@##################@@
@@#################@@@@@ @@@@###################@
@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@
@ &@@@@ @@@@ .......@@
@@ @@@@@@ @@@@@@ .......@@
@@ @@@@@@@@@@@@@@@@@ .......@@@
@@@ @@@@@@@@@@@ ......@@@@
@@@@ ......@@@@@
@@@@@@ ......@@@@@@
@@@@@@@ .....@@@@@@@@
@@@@@@@@@ .....@@@@@@@@@@
@@@@@@@@@@@@ ....@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/