- 选数
- 2015-05-02 13:32:54 @
改成scanf就没问题,怎么cin不行?。
/*************************************************************************
> File Name: 1128.cpp
> Author: Netcan
> Blog: http://www.netcan.xyz
> Mail: 1469709759@qq.com
> Created Time: Sat 02 May 2015 11:48:19 CST
************************************************************************/
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <sstream>
#include <deque>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <stack>
#include <set>
#include <numeric>
#include <utility>
#include <cstring>
using namespace std;
bool isPrime[10000005];
bool visited[10000005];
int x[25];
int N,K;
int ans = 0;
void DFS(int k, int i, int sum) {
if(k == K && isPrime[sum] && !visited[sum]) {
++ans;
return;
}
for(int j=i+1; j<=N; ++j) {
DFS(k+1, j, sum+x[j]);
}
}
int main()
{
ios::sync_with_stdio(false);
memset(isPrime, 1, sizeof(isPrime));
memset(visited, 0, sizeof(visited));
isPrime[1]=0;
for(int i=2;i<=10000000;++i)
if (isPrime[i])
for(int j=2;i*j<=10000000;++j)
isPrime[i*j]=0;
scanf("%d%d", &N, &K);
for(int i=1; i<=N; ++i)
cin >> x[i];
DFS(0, 0, 0);
cout << ans << endl;
return 0;
}
1 条评论
-
shadyqwq LV 8 @ 2016-03-02 17:05:00
cin比scanf慢。。输入大数据测一下时间你就知道了。。cin经常容易被卡时间
- 1