1 条题解
-
1
不明白这和深搜有什么关系。
思路
本题可以使用
限制数量的子集枚举
来解决。在 的数据范围下, 的时间复杂度可以通过。AC Code
#include<bits/stdc++.h> #define ll long long using namespace std; const ll N=25; ll n,k,a[N],ans; int main(){ scanf("%lld%lld",&n,&k); for(ll i=1;i<=n;i++) scanf("%lld",&a[i]); for(ll i=0;i<=(1<<n);i++) if(__builtin_popcount(i)==k){ // 限制数量为k ll cnt=0; for(ll j=0;j<n;j++) if(i&(1<<j)) cnt+=a[j+1]; bool flag=1; for(ll i=2;i*i<=cnt;i++) if(cnt%i==0){ flag=0; break; } if(flag) ans++; } printf("%lld",ans); return 0; }
- 1
信息
- ID
- 742
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 4
- 标签
- 递交数
- 158
- 已通过
- 68
- 上传者