时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 黄金 Gold
题目描述 Description

已知 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)

传送门 点此展开

dfs

#include<iostream>
#include<cstring> using namespace std; int a[30]={0},c[30],n,m,minn,tot=0,l=0;
bool b[30];
int su(int x)
{
int j;
j=2;
while(j*j<x&&x%j!=0)
j++;
if(j*j>x)
return 1;
else
return 0;
}
void zcl(int k,int t,int l)
{
int i;
if(l>=m)
{
if(su(t)==1)
tot++;
return;
}
for(i=k+1;i<=n;++i)
zcl(i,t+a[i],l+1);
}
int main()
{
memset(b,0,sizeof(b));
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
zcl(0,0,0);
cout<<tot;
return 0;
}

codevs 1008 选数的更多相关文章

  1. codevs——1008 选数

    1008 选数 2002年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 已知 n ...

  2. 1008 选数 2002年NOIP全国联赛普及组

    1008 选数 2002年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description ...

  3. NOIP 2002提高组 选数 dfs/暴力

    1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…, ...

  4. 【BZOJ-2732】集合选数 状压DP (思路题)

    2734: [HNOI2012]集合选数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1070  Solved: 623[Submit][Statu ...

  5. CODE VS1008选数

    #include<cstdlib> #include<cstdio> #include<iostream> #include<cmath> #inclu ...

  6. BZOJ 3930: [CQOI2015]选数 递推

    3930: [CQOI2015]选数 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pro ...

  7. bzoj 2734: [HNOI2012]集合选数 状压DP

    2734: [HNOI2012]集合选数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 560  Solved: 321[Submit][Status ...

  8. BZOJ3930: [CQOI2015]选数

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3930 容斥原理. 令l=(L-1)/k,r=R/k,这样找k的倍数就相当于找1的倍数. 设F[ ...

  9. 【BZOJ3930】选数(莫比乌斯反演,杜教筛)

    [BZOJ3930]选数(莫比乌斯反演,杜教筛) 题面 给定\(n,K,L,R\) 问从\(L-R\)中选出\(n\)个数,使得他们\(gcd=K\)的方案数 题解 这样想,既然\(gcd=K\),首 ...

随机推荐

  1. Python的中文处理

    一.使用中文字符 在python源码中如果使用了中文字符,运行时会有错误,解决的办法是在源码的开头部分加入字符编码的声明,下面是一个例子: #!/usr/bin/env python # -*- co ...

  2. java读取文件:文本文件

    一般使用串行方式读出或者写入文件.总的来说,使用输入流把文件内容读入内存,使用输出流把内存中的信息写出到文件.这些类位于java.io包下.输入和输出的类和方法往往是对应的 文本文件 先了解如何读写文 ...

  3. 1.22-1.24 Oozie企业使用案例

    一.将hive的表数据用sqoop抽取到mysql 1.编写oozie workflow和Coordinator ## [root@hadoop-senior oozie-apps]# pwd /op ...

  4. 【网络爬虫】【java】微博爬虫(一):小试牛刀——网易微博爬虫(自定义关键字爬取微博数据)(附软件源码)

    一.写在前面 (本专栏分为"java版微博爬虫"和"python版网络爬虫"两个项目,系列里所有文章将基于这两个项目讲解,项目完整源码已经整理到我的Github ...

  5. Flutter实战视频-移动电商-26.列表页_使用Provide控制子类-2

    26.列表页_使用Provide控制子类-2 主要实现功能,点击一级分类,二级分类跟着变.这里主要用哦我们的provide 新建provide provide文件夹下创建:child_category ...

  6. UVaLive 6847 Zeroes (找规律,水题)

    题意 :给定一个范围,然后让你求在这个范围内所有的数的阶乘末尾0的个数有多少种. 析:找规律,写几个就会发现每隔5个会增加一个0,因为要么乘10了,要么乘5了. 代码如下: #pragma comme ...

  7. codeforces 813C The Tag Game 树+dfs追击问题

    C. The Tag Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutpu ...

  8. Swift3.0 字典简单使用

    Dictionary //定义一个只能存放string 类型的字典 var dict:Dictionary<String,String> = ["一班":"2 ...

  9. Type中的3个bool属性: IsGenericType , IsGenericTypeDefinition , IsGenericParameter

    首先说下 IsGenericType 用3个实例说明: typeof(DateTime).IsGenericType : false typeof(List<int>).IsGeneric ...

  10. Codevs 1282 约瑟夫问题

    1282 约瑟夫问题  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 大师 Master 题解       题目描述 Description 有编号从1到N的N个小朋友在玩一种 ...