-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP2036.cpp
More file actions
47 lines (40 loc) · 683 Bytes
/
P2036.cpp
File metadata and controls
47 lines (40 loc) · 683 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m,vit[20],sum,ans,v[20],a[20];
void dfs(int pos)
{
if(pos >= n)
{
if(sum==m) ans++;
return;
}
if(sum == m)
{
ans++;
return;
}
for(int i = 1; i<=n;i++)
{
if(!vit[i] && a[i] < v[pos-1])
{
vit[i] = 1;
v[pos] = a[i];
sum++;
dfs(pos+1);
vit[i] = 0;
sum--;
}
}
}
signed main()
{
cin>>n>>m;
for(int i = 1;i <= n;i++)
cin>>a[i];
v[0] = 0x3f3f3f3f3f3f3f3f;
sort(a+1,a+n+1);
dfs(1);
cout<<ans<<endl;
return 0;
}