时间限制:1 秒

内存限制:32 兆

特殊判题:否

提交:1845

解决:780

题目描述:

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 contributions 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 Foundation 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 whether or not the number can be expressed
by the sum of some factorials.

Well, it is just a piece of case. For a given n, you will check if there are some xi, and let n equal to Σt (上标) i=1(下标) xi! (t≥1, xi≥0, xi = xj <==> i = j)

           t

     即 Σ  xi! (t≥1, xi≥0, xi = xj <==> i = j)

          i=1

    If the answer is yes, say "YES"; otherwise, print out "NO".

输入:

You will get a non-negative integer n (n≤1,000,000) from input file.

输出:

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

样例输入:
9
2
样例输出:
YES
YES
来源:
2007年上海交通大学计算机研究生机试真题

思路:

题意是问给出的数是否能表示成不同阶乘的和。

由于给出的n范围较小,最大的阶乘肯定不会超过10,因此尝试从10!开始逐步到1!看是否属于n的分解式即可。

代码:

#include <stdio.h>

int main(void)
{
int n, i;
int fac[10]; while (scanf("%d", &n) != EOF)
{
if (n == 0)
{
printf("NO\n");
continue;
}
fac[0] = 1;
for (i=1; i<10; i++)
fac[i] = fac[i-1]*i;
for (i=9; i>=0; i--)
{
if (n >= fac[i])
n -= fac[i];
if (n == 0)
break;
}
if (i == -1)
printf("NO\n");
else
printf("YES\n");
} return 0;
}
/**************************************************************
Problem: 1038
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/

九度OJ 1038:Sum of Factorials(阶乘的和) (DP、递归)的更多相关文章

  1. 【九度OJ】题目1179:阶乘 解题报告

    [九度OJ]题目1179:阶乘 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1179 题目描述: 输入n, 求y1=1!+3!+-m ...

  2. 九度OJ 1076:N的阶乘 (数字特性、大数运算)

    时间限制:3 秒 内存限制:128 兆 特殊判题:否 提交:6384 解决:2238 题目描述: 输入一个正整数N,输出N的阶乘. 输入: 正整数N(0<=N<=1000) 输出: 输入可 ...

  3. 九度OJ 1067:n的阶乘 (数字特性)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6476 解决:2471 题目描述: 输入一个整数n,输出n的阶乘 输入: 一个整数n(1<=n<=20) 输出: n的阶乘 样例 ...

  4. 九度OJ 1205 N阶楼梯上楼问题 (DP)

    题目1205:N阶楼梯上楼问题 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2817 解决:1073 题目描写叙述: N阶楼梯上楼问题:一次能够走两阶或一阶.问有多少种上楼方式. (要 ...

  5. 九度OJ 1345:XXX定律之画X (递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:361 解决:157 题目描述: 给你一个n,然后让你输出F(n) 规则是这样的,F(n)的输出结果是: F(n-1)     F(n-1) ...

  6. 九度OJ 1260:珍珠项链 (字符串处理、DP)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:101 解决:27 题目描述: 假设有一条珍珠项链,有很多珍珠,r代表红色, b代表蓝色, w代表白色. 假设你在某一处剪开之后,你会沿着顺时 ...

  7. 九度OJ 1161:Repeater(复制器) (递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1449 解决:508 题目描述: Harmony is indispensible in our daily life and no one ...

  8. 九度OJ 1040:Prime Number(质数) (递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5278 解决:2180 题目描述: Output the k-th prime number. 输入: k≤10000 输出: The k- ...

  9. 九度OJ 1035:找出直系亲属 (二叉树、递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2380 解决:934 题目描述:     如果A,B是C的父母亲,则A,B是C的parent,C是A,B的child,如果A,B是C的(外) ...

随机推荐

  1. ETL之Kettle

    Kettle是一款国外开源的ETL工具,纯java编写,可以在Window.Linux.Unix上运行. 说白了就是,很有必要去理解一般ETL工具必备的特性和功能,这样才更好的掌握Kettle的使用. ...

  2. Scala之Future

    一.简介 Future提供了一套高效便捷的非阻塞并行操作管理方案.其基本思想很简单,所谓Future,指的是一类占位符对象,用于指代某些尚未完成的计算的结果.一般来说,由Future指代的计算都是并行 ...

  3. 2016北京集训测试赛(八)Problem C: 直径

    Solution 一个定理: 把两棵树用一条边练成一棵树后, 树的直径在原来两棵树的四个直径端点中产生. 放到这一题, 我们通过DP先求出大树中以每个点为根的子树中的直径, 再取每棵小树中与其他树有连 ...

  4. iOS UI Element Usage

    Bars The Status Bar

  5. 解决unknown import path "golang.org/x/sys/unix": unrecognized import path "golang.org/x/sys"

    问题描述 当我们使用 go get.go install.go mod 等命令时,会自动下载相应的包或依赖包.但由于众所周知的原因,类似于 golang.org/x/... 的包会出现下载失败的情况. ...

  6. tomcat部署不成功 Deployment failure on Tomcat 6.x. Could not copy all resources to

    解决办法: tomcat服务并没有启动.上网搜索之后发现和大家犯的是一个毛病,原来工程中我引了一个包,后来这个包被我给删除了,但是因为已经发布过这个工程了,所以classpath中就有这个包名了,这样 ...

  7. dedecms调用文章发布日期

    <span>[field:pubdate function="MyDate('m-d',@me)"/]</span>

  8. 关于 OGRE 与 OSG 的简单比较 (转)

    关于 OGRE 与 OSG 的简单比较 1   前言 我曾经细致阅读过 OGRE 和 OSG 官方提供的文档,有<Pro OGRE 3D Programming>.OGRE自带手册(man ...

  9. java类中,成员变量赋值第一个进行,其次是静态构造函数,再次是构造函数

    如题是结论,如果有人问你Java类的成员初始化顺序和初始化块知识就这样回答他.下面是代码: package com.test; public class TestClass{ // 成员变量赋值第一个 ...

  10. js 中文校验并过滤掉中文

      js中文校验并过滤掉中文 CreateTime--2017年9月6日09:10:19 Author:Marydon 思路: 1.判断字符串中是否包含中文: 2.存在中文时,过滤掉. 举例: var ...