博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1775 && zoj 2358 Sum of Factorials
阅读量:2441 次
发布时间:2019-05-10

本文共 2480 字,大约阅读时间需要 8 分钟。

Sum of Factorials

Time Limit: 1000MS

Memory Limit: 30000K

Description

John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions to the foundations of mathematics, logic, quantum physics,meteorology, science, computers, and game theory. He was noted for a phenomenal memory and the speed with which he absorbed ideas and solved problems. In 1925 he received a B.S. diploma in chemical engineering from Zurich Institute and in 1926 a Ph.D. in mathematics from the University of Budapest. His Ph.D. dissertation on set theory was an important contribution to the subject. At the age of 20, von Neumann proposed a new definition of ordinal numbers that was universally adopted. While still in his twenties, he made many contributions in both pure and applied mathematics that established him as a mathematician of unusual depth. His Mathematical Foundations of Quantum Mechanics (1932) built a solid framework for the new scientific discipline. During this time he also proved the mini-max theorem of GAME THEORY. He gradually expanded his work in game theory, and with coauthor Oskar Morgenstern he wrote Theory of Games and Economic Behavior (1944).There are some numbers which can be expressed by the sum of factorials. For example 9,9=1!+2!+3! Dr. von Neumann was very interested in such numbers. So, he gives you a number n, and wants you to tell him whether or not the number can be expressed by the sum of some factorials.Well, it's just a piece of cake. For a given n, you'll check if there are some xi, and let n equal to Σ
1<=i<=tx
i!. (t >=1 1, xi >= 0, xi = xj iff. i = j). If the answer is yes, say "YES"; otherwise, print out "NO".

Input

You will get several non-negative integer n (n <= 1,000,000) from input file. Each one is in a line by itself.The input is terminated by a line with a negative integer.

Output

For each n, you should print exactly one word ("YES" or "NO") in a single line. No extra spaces are allowed.

Sample Input

9-1

Sample Output

YES

注意0!=1;

深度优先搜索

参考代码:

#include 
#include
using namespace std;int a[20];bool used[20];void work(){ a[0]=1; int mul=1; for (int i=1;a[i-1]<1000000+1;i++){ mul*=i; a[i]=mul; }}bool DFS(int x,int i){ if (a[i]==x || x==0) return true; if (a[i]>x) return false; for (;i<10;i++){ if (x-a[i]<0) continue; if (DFS(x-a[i],i+1)) return true; } return false;}int main(){ work(); int n; while (cin>>n&&n>=0){ if (n==0){ cout<<"NO"<

转载地址:http://wbbqb.baihongyu.com/

你可能感兴趣的文章
PG psql 变彩色显示
查看>>
SICP 练习 1.3
查看>>
pg 数据库HA 启动脚本的两个假设
查看>>
sql_log_bin在GTID复制下的一个现象
查看>>
双主+haproxy手工切换的一个注意点
查看>>
利用binlog2sql实现闪回
查看>>
mongos分片集群下db数量过多导致服务不可用
查看>>
故障处理--mongos count不准
查看>>
mongo3.0.9库命名的一个S级bug
查看>>
跨版本导入数据导致mysqld崩溃
查看>>
xtrabackup对于flush tables with read lock操作的设置
查看>>
Server has authorization schema version 3,but found a schema version 1 user
查看>>
WebSphere的池设置——线程池、连接池
查看>>
用户态调测工具(二):perror和man
查看>>
机器学习&深度学习入门历程
查看>>
LTP(Linux Test Project)学习(一)——LTP介绍
查看>>
LTP(Linux Test Project)学习(三)——LTP目录介绍
查看>>
DirtyCow CVE-2016-5195分析
查看>>
LTP(Linux Test Project)学习(七)——LTP提交补丁
查看>>
Linux 4.0亮点特性
查看>>