POJ - 3842 An Industrial Spy dfs(水)
题意:给你一串数字,最少一个,最多七个,问用这里面的数字能组成多少素数,不重复。
思路:之前还遍历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(水)的更多相关文章
- POJ -- 3842
An Industrial Spy Description Industrial spying is very common for modern research labs. I am such ...
- POJ 1321-棋盘问题(DFS 递归)
POJ 1321-棋盘问题 K - DFS Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I6 ...
- poj1564 Sum It Up dfs水题
题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...
- poj 1979 Red and Black(dfs水题)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- POJ 3256 DFS水题
枚举点 每次都搜一遍 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...
- poj 1321 棋盘问题 简单DFS
题目链接:http://poj.org/problem?id=1321 很久没有敲搜索了啊,今天敲了个水题练练手,哈哈.... 题目大意: 就是求在n*n的方格上放置k个棋子的方案数 代码: #inc ...
- POJ 2386——Lake Counting(DFS)
链接:http://poj.org/problem?id=2386 题解 #include<cstdio> #include<stack> using namespace st ...
- 【wikioi】1229 数字游戏(dfs+水题)
http://wikioi.com/problem/1229/ 赤裸裸的水题啊. 一开始我认为不用用完全部的牌,以为爆搜会tle.. 可是我想多了. 将所有状态全部求出,排序后暴力判断即可. (水题有 ...
- POJ 3321 Apple Tree(DFS序+线段树单点修改区间查询)
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25904 Accepted: 7682 Descr ...
随机推荐
- FastDFS图片服务器搭建
*FastDFS图片服务器搭建准备:1.需要libfastcommon安装包 选择最新稳定版(libfastcommon-1.0.36.tar.gz)2.需要FastDFS安装包 选择最新稳定版(fa ...
- linux SVN服务器创建版本库
1.安装svn服务 # yuminstall subversion 2.新建一个目录用于存储SVN所有文件 # mkdir /home/svn 3.在上面创建的文件夹中为项目 project_1 ...
- jstack命令dump线程信息
jstack命令dump线程信息 D:\Java\jdk1.8.0_05\bin>jstack.exe 6540 > dump17 6540为java 线程pid: 出来的dump17文件 ...
- [MST] Remove Model Instances from the Tree
In this lesson we will dive a bit more into the tree semantics of MST. In this lesson you will learn ...
- 利用Matlab自带的深度学习工具进行车辆区域检测与车型识别【Github更新!!!】(三)
前言 对前面的东西更新了一下.地方包括: 1.GUI的更新,更友好的用户界面 2.支持用手直接画车辆区域,并且识别出来 3.将proposal.detect.fine-grained classifi ...
- 一些标签库的学习和do的讨论
JSTL 核心标签库http://www.cnblogs.com/lihuiyy/archive/2012/02/24/2366806.html .do的讨论http://bbs.csdn.net/t ...
- 使用tinyxml2库解析xml
tinyxml2简介 tinyxml2是c++编写的轻量级的xml解析器,而且是开放源代码的,在一些开源的游戏引擎中用的比较多.源码托管在github上. 源码地址:https://github.co ...
- 查询SqlServer最近执行过的Sql
SELECT TOP 1000ST.text AS '执行的SQL语句' ,QS.execution_count AS '执行次数' ,QS.total_elapsed_time / 10000 AS ...
- linq replace with single call to FirstOrDefault 解决使用resharper产生的警告
使用resharper时对linq使用的FirstOrDefault 一直产生一个警告, 解决办法: 参考The Linq FirstOrDefault() Method and Null Resul ...
- nil / Nil / NULL / NSNull VS objc_msgSend
[NSNull null]是一个对象,其类为NSNULL(isa):里面没有任何变量.函数.和实现. nil的处理展示出消息机制的优越性,相对于函数调用的空指针处理. ENTRY objc_msgSe ...