[简单DP][完全背包]UVA 12955 Factorial

The factorial of a positive integer number N, denoted as N!, is defined as the product of all positiveinteger numbers smaller or equal to N. For example 4! = 4 × 3 × 2 × 1 = 24.

Given a positive integer number N, you have to write a program to determine the smallest numberk so that N = a1! + a2! + . . . + ak!, where every ai, for 1 ≤ i ≤ k, is a positive integer number.

Input

The input consists of several test cases. A test case is composed of a single line, containing one integernumber N (1 ≤ N ≤ 105).OutputFor each test case in the output your program must output the smallest quantity of factorial numberswhose sum is equal to N.

Sample Input

10

25

Sample Output

3

2

--------------------------------------------------------分割线----------------------------------------------------------------------------------

给你一个数n,问这个数拆成阶乘相加的形式,最少需要分解成多少个。

相当于对于每一个阶乘来说,都是一个物品,重量为阶乘的大小。价值为1。求最小的价值。

代码就不贴了。记得初始化问题,应该是为INF的。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值