50 lines
1015 B
C++
50 lines
1015 B
C++
#include <bits/stdc++.h>
|
||
|
||
using namespace std;
|
||
const int N = 30;
|
||
const int INF = 0x3f3f3f3f;
|
||
int a[N];
|
||
bool st[N];
|
||
int n, k;
|
||
int cnt;
|
||
// vector<int> path;
|
||
|
||
bool isPrime(int n) {
|
||
if (n < 2) return false;
|
||
for (int i = 2; i <= n / i; i++)
|
||
if (n % i == 0) return false;
|
||
return true;
|
||
}
|
||
void dfs(int step, int sum, int pre) {
|
||
if (step == k + 1) {
|
||
if (isPrime(sum)) {
|
||
cnt++;
|
||
// for (int i = 0; i < path.size(); i++) cout << path[i] << " ";
|
||
// cout << endl;
|
||
}
|
||
return;
|
||
}
|
||
for (int i = pre + 1; i <= n; i++)
|
||
if (!st[i]) {
|
||
st[i] = true;
|
||
// path.push_back(a[i]);
|
||
dfs(step + 1, sum + a[i], i);
|
||
// path.pop_back();
|
||
st[i] = false;
|
||
}
|
||
}
|
||
/*
|
||
4 3
|
||
3 7 12 19
|
||
|
||
3+7+19=29
|
||
答案:1
|
||
*/
|
||
int main() {
|
||
cin >> n >> k;
|
||
for (int i = 1; i <= n; i++) cin >> a[i];
|
||
dfs(1, 0, 0);
|
||
cout << cnt << endl;
|
||
return 0;
|
||
}
|