递归组合型的微变型
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
int ans;
int n,m;
int res = 0;
int a[N];
bool st[N];
int path[N];
bool is_prime(int x){
for(int i = 2; i <= x/i; i++){
if(x % i == 0) return false;
}
return true;
}
void dfs(int u, int res, int start){//u为深度,res为当前所有数的和 ,从当前start开始选,以防重复
if(u >= m){
// for(int i = 0; i < m; i++){
// cout << path[i] <<" ";
// }
// puts("");
if(is_prime(res)){
ans++;
}
return ;
}
for(int i = start; i < n; i++){
if(!st[i]){
st[i] = true;
path[u] = a[i];
dfs(u + 1, res + a[i],i + 1);
st[i] = false;
}
}
}
int main(){
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a[i];
}
dfs(0,0,0);
cout << ans << endl;
return 0;
}