全部评论 2

  • rt啥意思啊

    4天前 来自 浙江

    0
  • #include<bits/stdc++.h>
    using namespace std;
    bool isprime(int n){
        if(n==1) return false;
        else if(n==2) return true;
        else{
            for(int i=2;i*i<=n;i++){
                if(n%i==0) return false;
            }
            return true;
        }
    }
    int main(){
        int n,k,s2=0;
        cin>>n>>k;
        vector<int> x(n),y(n,0);
        for(int i=0;i<n;i++) cin>>x[i];
        fill(y.begin(),y.begin()+k,1);
        next_permutation(y.begin(),y.end());
        do{
            int s=0;
            for(int i=0;i<n;i++){
                if(y[i]==1) s+=x[i];
            }
            if(isprime(s)){
                s2++;
            }
        }while(next_permutation(y.begin(),y.end()));
        cout<<s2;
    }
    

    为何深搜?

    4天前 来自 浙江

    0

热门讨论