已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n)。从 n 个整数中任选 k 个整数相加,可分别得到一系列的和。例如当 n=4,k=3,4 个整数分别为 3,7,12,19 时,可得全部的组合与它们的和为:
    3+7+12=22  3+7+19=29  7+12+19=38  3+12+19=34。
  现在,要求你计算出和为素数共有多少种。
  例如上例,只有一种的和为素数:3+7+19=29)。

输入描述 Input Description

 键盘输入,格式为:
  n , k (1<=n<=20,k<n)
  x1,x2,…,xn (1<=xi<=5000000)

输出描述 Output Description

屏幕输出,格式为:
  一个整数(满足条件的种数)。

样例输入 Sample Input

4 3
3 7 12 19

样例输出 Sample Output

1

数据范围及提示 Data Size & Hint

(1<=n<=20,k<n)
(1<=xi<=5000000)

 
 
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio> using namespace std; int n,k,ans;
int a[]; bool judge(int n)
{
for(int i=;i*i<=n;i++)
if(n%i==)
return false;
return true;
} void DFS(int x,int tot,int goal)
{
if(x>=k)
{
if(judge(tot))
ans++;
return ;
} for(int i=goal+;i<=n;i++)
{
DFS(x+,a[i]+tot,i);
}
} int main()
{
cin>>n>>k;
for(int i=;i<=n;i++)
cin>>a[i];
DFS(,,);
cout<<ans;
return ;
}

最新文章

  1. Js dom操作总结
  2. IE8 margin: auto 无法居中
  3. shell script的连接符是逗号,不是英文的句号
  4. The 10th Zhejiang Provincial Collegiate Programming Contest
  5. HDU4704+费马小定理
  6. log4j 1.2配置(转载)
  7. You should rebuild using libgmp &gt;= 5 to avoid timing attack vulnerability.&quot;, PowmInsecureWarning
  8. OpenStack Block Storage安装配置use LVM
  9. ASP.NET MVC Model元数据
  10. linux ssh -l 命令运用
  11. 调用CMD命令的一个.NET工具类(MyWindowsCmd)
  12. Odoo-10开发环境配置与测试
  13. 在windows中把一个文件夹打成war包
  14. Java8新特性(待更新...)
  15. Linear transformations. 线性变换与矩阵的关系
  16. EasyUI创建DataGrid及冻结列的两种方式
  17. Python学习记录之----网络通信(一)
  18. mongodb 批量修改
  19. webGL之three.js入门3--材料篇
  20. Software Engineer’s path to the best annual performance review

热门文章

  1. Android Studio 中安装 apk 被拆分成多个 slice,如何禁止?
  2. bootstrap 翻页(对齐的链接)
  3. ios之UIActionSheet
  4. [LUOGU] P1063 能量项链
  5. OpenWrt 路由器如何让 lan 口主机获得 ipv6 网络访问 -- 知乎
  6. log4net.dll配置以及在项目中应用
  7. Debian7配置LAMP(Apache/MySQL/PHP)环境及搭建建站
  8. Python第三方库之openpyxl(2)
  9. 【LeetCode】Permutations(全排列)
  10. 如何部署 sources and javadoc jars