不知道哪错了
查看原帖
不知道哪错了
455139
qwcdim楼主2021/3/20 20:51
#include<iostream>
#include<algorithm>
using namespace std;
int n,k,a[21],ans;
bool sp(int hhh){
	for(int i=2;i<hhh;i++){
		if(hhh%i==0)return false;
	}
	return true;
}
void dfs(int hhh,int sum,int gs){
	if(gs<=0){
		if(sp(sum)==true)ans++;
		return;
	}
	for(int i=hhh;i<=n;i++){
		sum+=a[i];
		dfs(a[i],sum,gs-1);
	}
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	dfs(1,0,k);
	cout<<ans;
	return 0;
}

有没有dalao帮忙看看哪错了

2021/3/20 20:51
加载中...