社区讨论
#1TLE求条
P1036[NOIP 2002 普及组] 选数参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mj5588a5
- 此快照首次捕获于
- 2025/12/14 11:06 2 个月前
- 此快照最后确认于
- 2025/12/16 21:05 2 个月前
#1超时了,运行了1.7s,调了半天不知道错哪了。TAT
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
long long a[N],n,m,ans;
bool f(long long x){
if(x<2)return false;
for(int i=2;i<=sqrt(x);i++){
if(x%i==0){
return false;
}
}
return true;
}
void dfs(long long start,long long sum,long long num){
bool b=0;
if(num==m){
if(f(sum)){
ans++;
}
return;
}
for(int i=start;i<n;i++){
dfs(i+1,sum+a[i],num+1);
}
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a[i];
}
dfs(0,0,0);
cout<<ans;
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...