时间限制: 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. Linux日志分割脚本

    该脚本的功能是定时分割日志文件 #!/usr/bin/env bash #定时分割清理日志文件 #usage="Usage: logrotate (start|stop) file (lin ...

  2. httpclient:实现有验证码的模拟登陆

    //1.这种方式是先把验证码的图片下载到本地.并且根据网页解析获得token值//2.手动在控制台输入验证码//3.因为验证码图片已经下载下来,后面就可以使用图像文字识别package DoubanS ...

  3. Identity Server 4 原理和实战(完结)_Implicit Flow 实例

    oidc-client.js貌似是IdentityServer4的团队开发的 服务端的设置 在服务端新增一个Client 之后需要在angular客户端页建两个页面,对应这两个url才行 登出之后要跳 ...

  4. 使用AnimatorOverrideController动态更换animationclip注意事项

    http://www.ceeger.com/forum/read.php?tid=19138 public AnimationClip clip; Animator anim; void Awake( ...

  5. Android 跨应用调用Activity

    http://blog.csdn.net/ouyangliping/article/details/7972141 如何调用另外一个app应用的activity或者service,本文提供一个验证可行 ...

  6. 使用dynamic关键词 CS1969错误

    添加 Microsoft.CSharp.dll 引用即可 不需要添加using Microsoft.CSharp 这类namespace

  7. python的pip管理工具

    Python有两个著名的包管理工具easy_install.py和pip.在Python2.7的安装包中,easy_install.py是默认安装的,而pip需要我们手动安装. 在此进行编译安装pip ...

  8. Java程序员需要突破的技术要点

    一.源码分析 源码分析是一种临界知识,掌握了这种临界知识,能不变应万变,源码分析对于很多人来说很枯燥,生涩难懂. 源码阅读,我觉得最核心有三点:技术基础+强烈的求知欲+耐心. 我认为是阅读源码的最核心 ...

  9. 51Nod 1127 最短的包含字符串 (尺取法)

    #include <iostream> #include <algorithm> #include <string> #include <cstring> ...

  10. 简单的Javascript图片延迟加载库Echo.js

    简介: 和 Lazy Load 一样,Echo.js 也是一个用于图像延迟加载 JavaScript.不同的是 Lazy Load 是基于 jQuery 的插件,而 Echo.js 不依赖于 jQue ...