九度OJ 1038:Sum of Factorials(阶乘的和) (DP、递归)
时间限制: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
思路:
题意是问给出的数是否能表示成不同阶乘的和。
由于给出的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、递归)的更多相关文章
- 【九度OJ】题目1179:阶乘 解题报告
[九度OJ]题目1179:阶乘 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1179 题目描述: 输入n, 求y1=1!+3!+-m ...
- 九度OJ 1076:N的阶乘 (数字特性、大数运算)
时间限制:3 秒 内存限制:128 兆 特殊判题:否 提交:6384 解决:2238 题目描述: 输入一个正整数N,输出N的阶乘. 输入: 正整数N(0<=N<=1000) 输出: 输入可 ...
- 九度OJ 1067:n的阶乘 (数字特性)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6476 解决:2471 题目描述: 输入一个整数n,输出n的阶乘 输入: 一个整数n(1<=n<=20) 输出: n的阶乘 样例 ...
- 九度OJ 1205 N阶楼梯上楼问题 (DP)
题目1205:N阶楼梯上楼问题 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2817 解决:1073 题目描写叙述: N阶楼梯上楼问题:一次能够走两阶或一阶.问有多少种上楼方式. (要 ...
- 九度OJ 1345:XXX定律之画X (递归)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:361 解决:157 题目描述: 给你一个n,然后让你输出F(n) 规则是这样的,F(n)的输出结果是: F(n-1) F(n-1) ...
- 九度OJ 1260:珍珠项链 (字符串处理、DP)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:101 解决:27 题目描述: 假设有一条珍珠项链,有很多珍珠,r代表红色, b代表蓝色, w代表白色. 假设你在某一处剪开之后,你会沿着顺时 ...
- 九度OJ 1161:Repeater(复制器) (递归)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1449 解决:508 题目描述: Harmony is indispensible in our daily life and no one ...
- 九度OJ 1040:Prime Number(质数) (递归)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5278 解决:2180 题目描述: Output the k-th prime number. 输入: k≤10000 输出: The k- ...
- 九度OJ 1035:找出直系亲属 (二叉树、递归)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2380 解决:934 题目描述: 如果A,B是C的父母亲,则A,B是C的parent,C是A,B的child,如果A,B是C的(外) ...
随机推荐
- 【hibernate】hibernate不同版本的命名策略
===================================================hibernate 4命名策略如下================================ ...
- 解决官网下载jdk只有5k大小的错误
问题现象 官网 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 我选择linu ...
- mac 安装 word2016并破解
http://blog.csdn.net/zqbx7/article/details/53448280
- 前端模板adminlte
adminlet是一个前端模板,包含各种各样的功能,自己的网站可以根据需要进行修改:可以免费使用,也有收费增强版,界面如下: 参考: 1.https://adminlte.io/ 2.https:// ...
- SVN merge 三种方式
1.Merge a range of revisions 2.Reintegrate a branch 3.Merge two different trees ———————————————————— ...
- 2017.2.28 activiti实战--第六章--任务表单(一)动态表单
学习资料:<Activiti实战> 第六章 任务表单(一)动态表单 内容概览:本章要完成一个OA(协同办公系统)的请假流程的设计,从实用的角度,讲解如何将activiti与业务紧密相连. ...
- Notification(二)——PendingIntent的flag导致数据同样的问题
MainActivity例如以下: package cc.cu; import android.os.Bundle; import android.view.View; import android. ...
- 控制div属性
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 搭建rocketMq环境
大体流程按照文章https://blog.csdn.net/wangmx1993328/article/details/81536168逐步搭建,下面列出踩过的一些坑 1,自己的阿里云服务器端口没开放 ...
- 【解决方法】INF file txtsetup.sif is corrupt or missing /// 使用WinSetupFromUSB来U盘安装windows2003(不使用win PE系统)
[解决方法]INF file txtsetup.sif is corrupt or missing http://blog.csdn.net/zhyl8157121/article/details/8 ...