1 条题解
-
0
C++ :
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> using namespace std ; int n,m; int a[21]; int t = 0; int ans = 0; void in(); void serch(int x,int k); bool judge(int x); int main() { //freopen("select.in","r",stdin); //freopen("select.out","w",stdout); in(); serch(0,m); cout << ans << endl; return 0; } void in() { cin >> n >> m ; for (int i = 1;i<=n;i ++ ) { cin >> a[i]; } } void serch(int x,int k) { if (k == 0) { if (judge(t)) ans ++ ; return; } for (int i = x+1;i <= n-k+1;i ++ ) { t+=a[i]; serch(i,k-1); t-=a[i]; } } bool judge(int x) { if (x == 1)return false; if (x == 2)return true; int temp = floor(sqrt(x + 1)); for (int i = 2 ;i <= temp ; i ++ ) { if (x % i == 0) return false; } return true; }
- 1
信息
- ID
- 2671
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者