社区讨论
16分代码求调
P1036[NOIP 2002 普及组] 选数参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @m63jt74e
- 此快照首次捕获于
- 2025/01/19 19:42 去年
- 此快照最后确认于
- 2025/11/04 11:16 4 个月前
点2过了(悬关)
CPP#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
int n,k;
int x[25];
int st[25];
int cnt;
bool check(LL x){
for(int l=2;l*l<=x;l++){
if(x%l==0){
return false;
}
}
return true;
}
void dfs(int s,LL add){
if(s==k+1){
if(check(add)){
cnt++;
}
else{
return;
}
}
for(int i=1;i<=n;i++){
if(st[i]==0)
{
st[i]=1;
dfs(s+1,add+x[i]);
st[i]=0;
}
}
}
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>x[i];
dfs(1,0);
cout<<cnt;
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...