-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathDSA01021 - TỔ HỢP TIẾP THEO
69 lines (69 loc) · 2.39 KB
/
DSA01021 - TỔ HỢP TIẾP THEO
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
69
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
int n, k, s = 0, ok = 0;
cin >> n >> k;
int a[k + 1], b[k + 1];
map<int, int> m;
for (int i = 1; i <= k; i++)
{
cin >> a[i];
b[i] = a[i];
m[a[i]]++;
}
for (int i = k; i >= 1; i--)
{
if (a[i] != n - k + i)
{
ok = 1;
a[i]++;
for (int j = i + 1; j <= k; j++)
a[j] = a[j - 1] + 1;
break;
}
}
for (int i = 1; i <= k; i++)
{
if (m[a[i]] == 0)
s++;
}
if (ok == 0)
s = k;
cout << s << endl;
}
}
/* Do Xuan Huong
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@
@@@@@@@@@@@@&####################################@@@@@@@@@@@@
@@@@@@@@@@##########################################@@@@@@@@@
@@@@@@@@##############################################@@@@@@@
@@@@@@#################################################@@@@@@
@@@@@####################################################@@@@
@@@%#####################@@@@@@@@@@@######################@@@
@@@###################@@@@@@@@@@@@@@@@@####################@@
@@##################@@@@@@ @@@@@@##################@@
@@#################@@@@@ @@@@###################@
@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@
@ &@@@@ @@@@ .......@@
@@ @@@@@@ @@@@@@ .......@@
@@ @@@@@@@@@@@@@@@@@ .......@@@
@@@ @@@@@@@@@@@ ......@@@@
@@@@ ......@@@@@
@@@@@@ ......@@@@@@
@@@@@@@ .....@@@@@@@@
@@@@@@@@@ .....@@@@@@@@@@
@@@@@@@@@@@@ ....@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/