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

思路:之前还遍历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. nessus 漏洞扫描安装和使用

    介绍 Nessus 是目前全世界最多人使用的系统漏洞扫描与分析软件.总共有超过75,000个机构使用Nessus 作为扫描该机构电脑系统的软件.  软件特色 * 提供完整的电脑漏洞扫描服务, 并随时更 ...

  2. virt-install 创建虚拟机

    [root@kvm-server vm]# qemu-img create -f qcow2 centos69b-disk0.qcow2 10G Formatting 'centos69b-disk0 ...

  3. vue-quill-editor-upload : 实现vue-quill-editor上传图片到服务器

    vue-quill-editor-upload git: https://github.com/NextBoy/vu... A plug-in for uploading images to your ...

  4. ERROR in xxxx.js from UglifyJS——配置版本混杂版

    常规解决套路可以参考这篇:https://segmentfault.com/a/11... 我采用了上面的做法,依然没法解决.我采用的是vue-cli脚手架自动生成的项目结构: vue-cli版本 2 ...

  5. OpenJudge 1031 Lausanne Capitale Olympique

    Lausanne Capitale Olympique Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on  ...

  6. video : Write and Submit your first Linux kernel Patch

    http://v.youku.com/v_show/id_XNDMwNzc3MTI4.html After working with Linux (mostly as an advanced user ...

  7. HDU 1114 Piggy-Bank(一维背包)

    题目地址:HDU 1114 把dp[0]初始化为0,其它的初始化为INF.这样就能保证最后的结果一定是满的,即一定是从0慢慢的加上来的. 代码例如以下: #include <algorithm& ...

  8. HNU13377:Book Club(DFS)

    Problem description Porto's book club is buzzing with excitement for the annual book exchange event! ...

  9. Func委托和Action委托

    http://stackoverflow.com/questions/4317479/func-vs-action-vs-predicate The difference between Func a ...

  10. sklearn 词袋 CountVectorizer

    from sklearn.feature_extraction.text import CountVectorizer texts=["dog cat fish","do ...