codevs 1008 选数
已知 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)。
键盘输入,格式为:
n , k (1<=n<=20,k<n)
x1,x2,…,xn (1<=xi<=5000000)
屏幕输出,格式为:
一个整数(满足条件的种数)。
4 3
3 7 12 19
1
(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 选数的更多相关文章
- codevs——1008 选数
1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 已知 n ...
- 1008 选数 2002年NOIP全国联赛普及组
1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description ...
- NOIP 2002提高组 选数 dfs/暴力
1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…, ...
- 【BZOJ-2732】集合选数 状压DP (思路题)
2734: [HNOI2012]集合选数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1070 Solved: 623[Submit][Statu ...
- CODE VS1008选数
#include<cstdlib> #include<cstdio> #include<iostream> #include<cmath> #inclu ...
- BZOJ 3930: [CQOI2015]选数 递推
3930: [CQOI2015]选数 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pro ...
- bzoj 2734: [HNOI2012]集合选数 状压DP
2734: [HNOI2012]集合选数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 560 Solved: 321[Submit][Status ...
- BZOJ3930: [CQOI2015]选数
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3930 容斥原理. 令l=(L-1)/k,r=R/k,这样找k的倍数就相当于找1的倍数. 设F[ ...
- 【BZOJ3930】选数(莫比乌斯反演,杜教筛)
[BZOJ3930]选数(莫比乌斯反演,杜教筛) 题面 给定\(n,K,L,R\) 问从\(L-R\)中选出\(n\)个数,使得他们\(gcd=K\)的方案数 题解 这样想,既然\(gcd=K\),首 ...
随机推荐
- http://blog.sina.com.cn/s/blog_6145ed810102vr8k.html
http://blog.sina.com.cn/s/blog_6145ed810102vr8k.html
- ubuntu系统下挂载新的硬盘
参考 http://zwkufo.blog.163.com/blog/static/258825120141283942244/ http://blog.csdn.net/caicai2526 ...
- OO易错点总结
在写子类的构造函数时,要在初始化列表中指定使用的父类的构造函数并完成其初始化,如下例: AudioBook(const string& bookname, const string& ...
- vue.eslintrc.js常用配置
vue.eslintrc.js module.exports = { root: true, env: { node: true }, extends: [ "plugin:vue/esse ...
- C# interface 的特性 无法被implement class继承
最近做interface添加特性后,implement class 无法继承. 微软要求class是实现Interface而不是继承,所以我们必须手动添加特性,而不能自动继承. 对于abstract ...
- 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:6. 设备事件上报
文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...
- c3p0连接池的简单使用和测试1
- JPA_day01
- [題解](最短路/二分)luogu_P1462通往奧格瑞瑪的道路
看到最大的最小值應該想到二分答案,這樣就解決了最小點權的問題,判血量就很好說,直接比較就行, 一個點是二分點權數組,複製一份然後排序,二分下標,速度較快 這麼簡單的題我竟然寫了這麼長時間 #inclu ...
- B.出题人的女装
链接:https://ac.nowcoder.com/acm/contest/358/B 题意: 出题人早上起床就打算穿衣服,他有两箱衣服,因为懒,他在这两天只打算打开一个箱子. 两个箱子中一个有n件 ...