1008 选数

来源:互联网 发布:jsp网上订餐系统源码 编辑:程序博客网 时间:2024/05/19 02:30
#include <bits/stdc++.h>using namespace std;int num [105];int n, k;int c = 0;void isp (int x){        for (int i = 2; i <= sqrt (x); i ++){                if (x % i == 0){                        return;                }        }        c ++;        return;}void sel (int a, int t, int s){        if (t == k){                //cout << s << endl;                isp (s);                return;        }        else{                for (int i = a + 1; i <= n - k + t + 1; i ++){                        sel (i, t + 1, s + num [i]);                }        }        return;}int main (){        cin >> n >> k;        for (int i = 1; i<= n; i ++){                cin >> num [i];        }        sel (0, 0, 0);        cout << c;        return 0;}

原创粉丝点击