当前位置:网站首页>【洛谷】P1036 [NOIP2002 普及组] 选数(DFS)
【洛谷】P1036 [NOIP2002 普及组] 选数(DFS)
2022-04-22 15:55:00 【percation】
递归组合型的微变型
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
int ans;
int n,m;
int res = 0;
int a[N];
bool st[N];
int path[N];
bool is_prime(int x){
for(int i = 2; i <= x/i; i++){
if(x % i == 0) return false;
}
return true;
}
void dfs(int u, int res, int start){
//u为深度,res为当前所有数的和 ,从当前start开始选,以防重复
if(u >= m){
// for(int i = 0; i < m; i++){
// cout << path[i] <<" ";
// }
// puts("");
if(is_prime(res)){
ans++;
}
return ;
}
for(int i = start; i < n; i++){
if(!st[i]){
st[i] = true;
path[u] = a[i];
dfs(u + 1, res + a[i],i + 1);
st[i] = false;
}
}
}
int main(){
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a[i];
}
dfs(0,0,0);
cout << ans << endl;
return 0;
}
版权声明
本文为[percation]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_45866781/article/details/124344740
边栏推荐
- Huawei cloud media Zha Yong: Huawei cloud's technical practice in the field of video AI transcoding
- All the goods in the files backed up by Taobao assistant were put on the shelves again
- Small pit on the definition of two-dimensional or multi-dimensional array / slice in go language
- Terraform best practices: typical file layout
- 342-Leetcode 字符串中的第一个唯一字符
- How can AI intelligent video technology be applied to the scene of daily maintenance and supervision of cultural relics and historic buildings?
- Send custom fields using Tencent cloud custom alarm SMS interface
- 电脑任务栏卡住
- CiteSpace installation and use tutorial
- 一文学会JVM性能优化
猜你喜欢

Future development direction of construction industry: digital chemical plant management system

citespace安装和使用教程

每周推荐短视频:存量时代如何重构企业核心竞争力?

面试官:请说说==操作符和equals(),从基本数据类型和引用数据类型两个角度谈谈

OSPF的详细讲解、分类,还有实验讲解

建筑业未来的发展方向:数字化工厂管理系统
How redis solves the performance bottleneck caused by frequent command round trips!

Crystal Chem β-乳球蛋白 ELISA 试剂盒 II说明书

【合泰HT32F52352定时器的使用】

Fe of mL: combined with a case of kaggle competition, study the thinking framework of feature engineering
随机推荐
推进制造业数字化转型的几个建议
Jmeter 存取Sql Server带有逗号‘,‘的数据到csv文件
Weekly recommended short video: how to reconstruct the core competitiveness of enterprises in the stock era?
Sed in shell script
Immundiagnostik IDK TurbiPEL测定分析
Tencent cloud fortress machine opens OTP authentication
sql语句———多表联查
Altium designer除了GND以外的Nets自动布线
‘telnet‘ 不是内部或外部命令也不是可运行的程序或批处理文件
Will NFT impact the native culture of the Internet?
[binary number] same tree
jsquery.xxx.js和jsquery.xxx.min.js的区别
[model] state space average modeling - step down
LeetCode每日一题——824. 山羊拉丁文
Redis optimization series (I) building redis master-slave based on docker
类人猿手游内存技术教程
使用腾讯云自定义告警短信接口发送自定义字段
CiteSpace installation and use tutorial
Zero negative comment on the reputation of Jihu products BAIC Blue Valley has captured the hearts of users with high-end hard core strength
396.旋转函数
