T1008 选数 codevs
2024-09-04 14:35:49
已知 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 ;
}
最新文章
- Js dom操作总结
- IE8 margin: auto 无法居中
- shell script的连接符是逗号,不是英文的句号
- The 10th Zhejiang Provincial Collegiate Programming Contest
- HDU4704+费马小定理
- log4j 1.2配置(转载)
- You should rebuild using libgmp >;= 5 to avoid timing attack vulnerability.";, PowmInsecureWarning
- OpenStack Block Storage安装配置use LVM
- ASP.NET MVC Model元数据
- linux ssh -l 命令运用
- 调用CMD命令的一个.NET工具类(MyWindowsCmd)
- Odoo-10开发环境配置与测试
- 在windows中把一个文件夹打成war包
- Java8新特性(待更新...)
- Linear transformations. 线性变换与矩阵的关系
- EasyUI创建DataGrid及冻结列的两种方式
- Python学习记录之----网络通信(一)
- mongodb 批量修改
- webGL之three.js入门3--材料篇
- Software Engineer’s path to the best annual performance review
热门文章
- Android Studio 中安装 apk 被拆分成多个 slice,如何禁止?
- bootstrap 翻页(对齐的链接)
- ios之UIActionSheet
- [LUOGU] P1063 能量项链
- OpenWrt 路由器如何让 lan 口主机获得 ipv6 网络访问 -- 知乎
- log4net.dll配置以及在项目中应用
- Debian7配置LAMP(Apache/MySQL/PHP)环境及搭建建站
- Python第三方库之openpyxl(2)
- 【LeetCode】Permutations(全排列)
- 如何部署 sources and javadoc jars