题意:给你一串数字,最少一个,最多七个,问用这里面的数字能组成多少素数,不重复。

思路:之前还遍历10000000的每一个素数,结果超时,后来发现直接dfs就可以了,只是标记一下做过的数。

 #pragma comment(linker, "/STACK:1000000000")
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt", "w", stdout)
#define MAXN 10000005
using namespace std;
bool vis[MAXN], done[MAXN], has[];
int p[];
char s[];
int cnt[], a[];
int n, ans;
void dfs(int m, int res){
if(done[res]) return;
if(!vis[res]){
ans++;
}
done[res] = true;
if(m > n) return;
for(int i = ; i <= n; i++){
if(has[i]) continue;
has[i] = true;
dfs(m + , res * + (s[i] - ''));
dfs(m + , res);
has[i] = false;
}
}
int main()
{
//IN;
//OUT;
int T;
memset(vis, , sizeof(vis));
int o = ;
vis[] = vis[] = true;
for(int i = ; i <= ; i++){
if(!vis[i]){
p[o++] = i;
}
for(int j = * i; j <= ; j += i){
vis[j] = true;
}
}
scanf("%d", &T);
while(T--){
//memset(cnt, 0, sizeof(cnt));
ans = ;
memset(has, , sizeof(has));
memset(done, , sizeof(done));
scanf("%s", s + );
n = strlen(s + );
dfs(, );
printf("%d\n", ans);
}
return ;
}

POJ - 3842 An Industrial Spy dfs(水)的更多相关文章

  1. POJ -- 3842

    An Industrial Spy   Description Industrial spying is very common for modern research labs. I am such ...

  2. POJ 1321-棋盘问题(DFS 递归)

    POJ 1321-棋盘问题 K - DFS Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I6 ...

  3. poj1564 Sum It Up dfs水题

    题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...

  4. poj 1979 Red and Black(dfs水题)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  5. POJ 3256 DFS水题

    枚举点 每次都搜一遍 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...

  6. poj 1321 棋盘问题 简单DFS

    题目链接:http://poj.org/problem?id=1321 很久没有敲搜索了啊,今天敲了个水题练练手,哈哈.... 题目大意: 就是求在n*n的方格上放置k个棋子的方案数 代码: #inc ...

  7. POJ 2386——Lake Counting(DFS)

    链接:http://poj.org/problem?id=2386 题解 #include<cstdio> #include<stack> using namespace st ...

  8. 【wikioi】1229 数字游戏(dfs+水题)

    http://wikioi.com/problem/1229/ 赤裸裸的水题啊. 一开始我认为不用用完全部的牌,以为爆搜会tle.. 可是我想多了. 将所有状态全部求出,排序后暴力判断即可. (水题有 ...

  9. POJ 3321 Apple Tree(DFS序+线段树单点修改区间查询)

    Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25904   Accepted: 7682 Descr ...

随机推荐

  1. windows下matlab代码到ubuntu下中文注释出现乱码

    转自:https://blog.csdn.net/kouyi5627/article/details/81513329 环境:Ubuntu18.04,Matlab R2017b. 把matlab文件从 ...

  2. HTTP——学习笔记(8)

    HTTP中的一些协议内容会限制某些网站的功能使用 比如,Facebook这类的社交网站,需要实时地观察到海量用户公开发布的内容,而HTTP中的以下标准就会成为瓶颈: 一条连接上只可发送一个请求 请求只 ...

  3. HTTP——状态码

    (转载) 完整的 HTTP 1.1规范说明书来自于RFC 2616,你可以在http://www.talentdigger.cn/home/link.php?url=d3d3LnJmYy1lZGl0b ...

  4. Qt之图形(简笔画-绘制卡通蚂蚁)

    简述 关于简笔画的介绍很多,有动物.水果.蔬菜.交通工具等,通常会对绘制一步步进行拆分.组合.然后绘制为我们想要的结果. 下面来介绍另外的一个种类:昆虫类-卡通蚂蚁. 简述 绘制 效果 源码 绘制 效 ...

  5. Redis Java调用

    Redis Java调用 package com.stono.redis; import redis.clients.jedis.Jedis; public class RedisJava { pub ...

  6. 局部加权回归、欠拟合、过拟合 - Andrew Ng机器学习公开课笔记1.3

    本文主要解说局部加权(线性)回归.在解说局部加权线性回归之前,先解说两个概念:欠拟合.过拟合.由此引出局部加权线性回归算法. 欠拟合.过拟合 例如以下图中三个拟合模型.第一个是一个线性模型.对训练数据 ...

  7. JavaScript中的Array对象方法调用

    方法concat for  循环与for in 循环 <html> <head> <script type="text/javascript"> ...

  8. C语言:constkeyword、结构体

    前几节内容的解说,主要是内存地址及指针的分析.这一节解说一下easy混淆的keywordconstant及结构体的知识. 一.constkeyword 1. 字符常量的指针 char const *p ...

  9. 51nod-1322: 关于树的函数

    [传送门:51nod-1322] 简要题意: 给出n个点的两棵无根树,编号都是从0到n-1 现在每棵树任意选出一条边割断,设第一棵树选出的边为e1,第二棵树选出的边为e2 很显然割断后两棵树各分成了四 ...

  10. How to Download Windows 10 Spotlight/Lock Screen Images

    http://www.online-tech-tips.com/windows-10/download-windows-10-spotlight-lock-screen-images/ 图片位置 C: ...