DFS(dfs)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2212
DFS
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6322 Accepted Submission(s): 3898
For example ,consider the positive integer 145 = 1!+4!+5!, so it's a DFS number.
Now you should find out all the DFS numbers in the range of int( [1, 2147483647] ).
There
is no input for this problem. Output all the DFS numbers in increasing
order. The first 2 lines of the output are shown below.
2
......
#include<cstdio>
#include<algorithm>
using namespace std;
//#define N 8776444321ll//要在后面加ll 这样不会超int
#define ll long long
const ll N = ;
ll ans[];
int c ;
int f[],g[];
int a[];
int ck(ll sum)
{
for(int i = ; i < ; i++) f[i] = ,g[i] = ;
ll v = sum;
ll tm = ;
while(v)
{
tm+=a[v%];
f[v%]++;
v/=;
}
v = tm;
while(tm)
{
g[tm%]++;
tm/=;
}
for(int i = ;i < ; i++) if( f[i]!=g[i] ) return -;
return v;
}
void dfs(int cur, ll sum)
{
ll res = ck(sum);
if(sum>N) return ;
if(res!=-) ans[c++] = res;
for(int i = cur ; i >= ; i-- )
{
if(sum==&&i==) continue;
dfs(i,sum*+i);
}
}
int main()
{
a[] = a[] = ;
for(int i = ; i < ; i++)
a[i] = a[i-]*i;
c = ;
dfs(,);
sort(ans,ans+c);
for(int i = ; i < c ; i++)
printf("%lld\n",ans[i]);
return ;
}
其实得到输出结果后可以直接打表:
#include <cstdio>
using namespace std;
int main()
{
puts("");
puts("");
puts("");
puts("");
return ;
}
DFS(dfs)的更多相关文章
- PAT 甲级 1018 Public Bike Management (30 分)(dijstra+dfs,dfs记录路径,做了两天)
1018 Public Bike Management (30 分) There is a public bike service in Hangzhou City which provides ...
- BZOJ 4196: [Noi2015]软件包管理器 [树链剖分 DFS序]
4196: [Noi2015]软件包管理器 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1352 Solved: 780[Submit][Stat ...
- UVA 291 The House Of Santa Claus (DFS求一笔画)
题意:从左下方1开始,一笔画出圣诞老人的屋子(不过话说,圣诞老人的屋子是这样的吗?这算是个屋子么),输出所有可以的路径. 思路:贴代码. #include <iostream> #incl ...
- Shredding Company(dfs)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3519 Accepted: 2009 Description You h ...
- 素数回文(dfs,有bug)
素数回文 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- [Swust OJ 799]--Superprime Rib(DFS)
题目链接:http://acm.swust.edu.cn/problem/799/ Time limit(ms): 1000 Memory limit(kb): 10000 Description ...
- Lake Counting (DFS)
N*M的园子,雨后积起了水.八连通的积水背认为是连接在一起的.请求出园子里总共有多少水洼? dfs(Depth-First Search) 八个方向的简单搜索.... 深度优先搜索从最开始的状态出 ...
- BFS和DFS详解
BFS和DFS详解以及java实现 前言 图在算法世界中的重要地位是不言而喻的,曾经看到一篇Google的工程师写的一篇<Get that job at Google!>文章中说到面试官问 ...
- 训练[2]-DFS
题目A: 题目B[https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pro ...
随机推荐
- Java I/O---Reader & Writer(字符流)
1.Reader & Writer 当我们初次看见Reader和Writer类时,可能会以为这是两个用来替代InputStream和OutputStreamt的类,但实际上并非如此. 尽管一些 ...
- C# 内存模型
C# 内存模型 This is the first of a two-part series that will tell the long story of the C# memory model. ...
- BZOJ 4816 数字表格
首先是惯例的吐槽.SDOI题目名称是一个循环,题目内容也是一个循环,基本上过几年就把之前的题目换成另一个名字出出来,喜大普奔亦可赛艇.学长说考SDOI可以考出联赛分数,%%%. 下面放解题报告.并不喜 ...
- su 和 sudo 命令的区别-转载
link 一. 使用 su 命令临时切换用户身份 1.su 的适用条件和威力 su命令就是切换用户的工具,怎么理解呢?比如我们以普通用户beinan登录的,但要 ...
- 2.Nginx日常维护技巧
Nginx日常维护技巧 Nginx配置正确性检查 nginx提供了配置文件调试功能,可以快速定义配置文件存在的问题.执行如下命令检测配置文件的正确性: [root@localhost 桌面]# whi ...
- cleanMyMac
想看外国网站可以找我,facebook.youtube.XX大片等,只要8元钱,无限制用到服务器关闭.看大片流畅不成问题 需要cleanMyMac的请加微信只要10或直接拍 http://a.p6ff ...
- 最优化算法:BFGS算法全称和L-BFGS算法全称
在最优化算法研究中按时间先后顺序出现了许多算法包括如下几种,这里介绍下他们的全称和英文名称: 1.最速下降法(Gradient descent) 2.牛顿法(Newton method) 3. 共轭梯 ...
- Django学习日记05_模板_模板语言
Variables 在模板中,使用两个大括号包含变量的方式来使用变量: {{ name }} 该变量应该作为键值对中的键,在Context中能被查找到. Tags 模板中使用Tags来进行简单的逻辑: ...
- VIM常见用法总结
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- 面试经验And总结
作为一个实习生,我大二即将读完,因为自己是大专的和本科没法比,没有他们的 知识基础,没有他们的充裕的时间,没有那个本科毕业证,没有学位证书.作为一个大专生我在找工作的时候总是充满了自卑,可自己有事那种 ...