__救救孩子吧!!!__
查看原帖
__救救孩子吧!!!__
313616
Gsmdog_H楼主2020/10/2 14:46
#include<iostream>
#include<cmath>
using namespace std;
int ans , n , k , a[50] = {0};

bool zs(int x){
	if(x == 2)
		return true;
	if(x == 1)
		return false;
	if(x == 0)	
		return false;
	
	for(int i = 2 ; i <= sqrt(x) ; ++ i){
		if(x % i == 0)
			return false;
		else 
			return true;
	}
}

void dfs(int x, int sum , int t){
	if(x == k){
		if(zs(sum))
			ans ++;
		return;
	}
	
	for(int i = t; i <= n ; ++i){
		dfs(x + 1 , sum + a[i] , i + 1);
	}
}

int main(){
	cin >> n >> k;
	for(int i = 1; i <= n ; ++i){
		cin >> a[i];
	}
	
	dfs(0 , 0 , 1);
	
	cout << ans;
	
	return 0;
}

WA了仨

2020/10/2 14:46
加载中...