问(玄关
  • 板块学术版
  • 楼主HX_ztx
  • 当前回复8
  • 已保存回复8
  • 发布时间2024/11/28 11:53
  • 上次更新2024/11/28 15:58:59
查看原帖
问(玄关
945933
HX_ztx楼主2024/11/28 11:53

题目,是的,只是一个橙的搜索。。。

哪错了啊啊啊啊

#include<bits/stdc++.h>
using namespace std;
const int N=100+10;
int n,k,a[N],ans=0;
bool ss(int x){
	if(x<2)return 0;
	for(int i=2;i*i<=x;i++){
		if(!x%i)return 0;
	}
	return 1;
}
void dfs(int x,int y,int w){//现在位置,已选,和 
	if(x>n)return ;
	if(y==k){
		if(ss(w))ans++;
		return ;
	}
//	if(n-x+1+y<k)return; 
	dfs(x+1,y+1,w+a[x]);
	dfs(x+1,y,w);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	dfs(0,0,0);
	cout<<ans;
	return 0;
}
2024/11/28 11:53
加载中...