哪里错了
查看原帖
哪里错了
1029100
hhb123456楼主2023/7/18 21:34
#include<bits/stdc++.h>
using namespace std;
bool f(int x){
	if(x==1)return false;
	if(x==2)return true; 
	for(int i=2;i<=sqrt(x);i++)
		if(x%i==0)return 0;
	return 1; 
} 
int n,k,ans,a[25],b[25],c[25];
void d(int x,int sum,int t){
	if(x==k){
		if(f(sum)&&c[sum]==0)ans++;
		return ;
	}
	for(int i=1;i<=n;i++){
		if(b[i]==0,a[i]>t){
			b[i]=1;
			d(x+1,sum+a[i],a[i]);
			b[i]=0;
		} 
	}
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	d(0,0,0);
	cout<<ans;
	return 0;
}

2023/7/18 21:34
加载中...