博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeVS 1008 选数(DFS)
阅读量:6943 次
发布时间:2019-06-27

本文共 787 字,大约阅读时间需要 2 分钟。

题目大意:

 

解题:

#include 
#include
using namespace std;int n ,k ;int arr[21];int res;bool isPrime(int a){ for(int i = 2; i < sqrt(a)+1; i++) if(a % i == 0) return false; return true;}void search(int start,int count,int total){ if(count == k && isPrime(total)) res++; if(count == k && isPrime(total) == false) return; if(count > k ) return; for(int i = start; i < n; i++) { total += arr[i]; count++; search(i+1,count,total); count--; total -=arr[i]; }}int main(){ cin >> n >> k; for(int i = 0; i < n; i++) { cin >> arr[i]; } res = 0; search(0,0,0); cout << res << endl; return 0;}

 

转载于:https://www.cnblogs.com/zyqBlog/p/7426337.html

你可能感兴趣的文章
CSS3-2D 转换
查看>>
Android <Android应用开发实战> 资源类型<二>
查看>>
日期选择器datetimepicker--选择时分秒
查看>>
[SCOI2010]幸运数字
查看>>
关于EF Unit of Work Repository的简单用法
查看>>
数组,排序,枚举
查看>>
内置方法
查看>>
JVM系列五:JVM监测&工具[整理中]
查看>>
第二周
查看>>
quick-cocos2d-x3.2 scheduler使用注意事项
查看>>
freemarker写select组件(二)
查看>>
微信小程序 app.json 配置
查看>>
ROCKETMQ——2主2从集群部署
查看>>
从51aspx首页上提取的qq和阿里旺旺在线客服
查看>>
横向纵向菜单制作 Jquery
查看>>
一些做设计挺不错的网站
查看>>
js事件
查看>>
Webpack+Typescript 简易配置
查看>>
docker 中nginx域名解析,反向代理
查看>>
【112】生活新体验
查看>>