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

思路:之前还遍历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. POJ 1975 Median Weight Bead

    Median Weight Bead Time Limit: 1000ms Memory Limit: 30000KB This problem will be judged on PKU. Orig ...

  2. Linux修改Linux默认打开方式

    从总体上讲 /etc/gnome/defaults.list 保存了全局的打开方式 /.local/share/applications/mimeapps.list 保存了个人的打开方式当两着不一致是 ...

  3. SJTU 1319. countColors

    题目描写叙述 知道 psypaint 怎么用吗?在巫女系统全面普及的未来世界.非常少人会知道 psypaint 的使用方法. 而身处在公安局作为监视官的朱同学.为了办案须要研究起了 psypaint ...

  4. C语言之文件操作04——输入矩阵a,b,求乘积c,并打印a,b,c到文件

    //文件与数组结合 /* ================================================================= 题目:输入矩阵a,b,求乘积c,并打印a, ...

  5. 在EA中将画出的ER图转换成SQL脚本

    在进行数据库设计的时候,想着正好安装着EA软件呢,看能不能用EA画ER模型.结果发现不仅能画.并且还能进行整套数据库设计(生成SQL脚本). 以下以机房收费系统用户--学生为例.学生能够查看剩余金额. ...

  6. ASCII中的控制字符含义

    十进制 十六进制 控制字符 转义字符 说明 Ctrl + 下列字母 0 00 NUL \0 Null character(空字符) @ 1 01 SOH   Start of Header(标题開始) ...

  7. 4. idea常用快捷键设置(改为eclipse相似)

    转自:https://blog.csdn.net/loveer0/article/details/82697877 idea常用快捷键设置(改为eclipse相似) 目录 idea常用快捷键设置改为e ...

  8. mybatis如何成功插入后获取自增长的id

    使用mybatis向数据库中插入一条记录,如何获取成功插入记录的自增长id呢? 需要向xml配置中加上一下两个配置: <insert id="add" useGenerate ...

  9. PostgreSQL Replication之第九章 与pgpool一起工作(5)

    9.5 检查复制 如果所有的节点都处于开机并运行的状态.我们就可以在集群上运行我们的第一个操作了.在我们的例子中,我们将简单地连接到pgpool并创建一个新的数据库.createdb 是一个命令行工具 ...

  10. ACM训练联盟周赛(第一场)

    B:Zeratul与Xor 题目描述 Xor(按位异或),对应C++中的“^”运算符. Zeratul给出了一个数列A[n](n≤105),要做q(q≤105)组动作,这些动作包括: 1  a:数列中 ...