acdream 1431 Sum vs Product
来源:互联网 发布:ubuntu arm 国内源 编辑:程序博客网 时间:2024/06/05 14:37
Sum vs Product
Problem Description
Peter has just learned mathematics. He learned how to add, and how to multiply. The fact that 2 + 2 = 2 × 2 has amazed him greatly. Now he wants find more such examples. Peters calls a collection of numbers beautiful if the product of the numbers in it is equal to their sum.
For example, the collections {2, 2}, {5}, {1, 2, 3} are beautiful, but {2, 3} is not.
Given n, Peter wants to find the number of beautiful collections with n numbers. Help him!
Input
Output
Sample Input
25
Sample Output
13
Hint
Source
Manager
题解及代码:
通过打表前几项我们会发现构成n,比如n=5时,其形式之一是1 1 2 2 2,都是这种很多1,然后其他数字组合的形式。那么我们就可以枚举除了1以外的数字的组合,来计算sum[n]。比如数字组合为2 3 4,那么根据公式我们知道2*3*4=24,2+3+4=9,那么我们还需要补上15个1,加上2 3 4 这三个数字,总共是18个数字,那么2 3 4必然属于sum[18]里面的一中情况。得到验证,这样我们就能用dfs来求出所有的情况数了。
下面的代码是dfs的代码,因为怕超时的缘故,题目AC的代码是打表之后交的。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;int sum[510];void init(){ memset(sum,0,sizeof(sum));}void dfs(int nt,int nu,int su,int k){ for(int i=k;i<=500;i++) { if(nu*i>1000) break; sum[nu*i-su-i+nt+1]++; //printf("%d %d %d %d %d\n",nu,su,i,nt+1,nu*i-su-i+nt+1); dfs(nt+1,nu*i,su+i,i); }}int main(){ init(); for(int i=2;i<=500;i++) dfs(1,i,i,i); for(int i=2;i<=500;i++) printf("%d,",sum[i]); return 0;}
- acdream 1431 Sum vs Product
- ACdream 1431 Sum vs Product
- ACdream 1431Sum vs Product
- Acdream 1431Sum vs Product(dfs+剪枝)
- Sum vs Product(ACdream) —— dfs
- ACdream1431-Sum vs Product
- ACdream: Sum
- Codeforces Gym 100339I Sum vs Product 剪枝搜索
- acdream(16) J-Sum
- ACdream 1154 Lowbit Sum
- acdream--Matrix sum
- acdream 1171 Matrix sum
- ACdream 1156_LCP SUM
- ACdream P1174 Sum
- ACdream 1139(Sum-逆元)
- ACdream OJ 1154 Lowbit Sum
- Sum of product
- ACdream 1154 Lowbit Sum(数学:推理)
- 嵌入式 GDB调试死锁示例
- 深入理解javascript原型和闭包(14)--从自由变量到作用域链
- 【原创】关于C#访问修饰符protected internal的说明
- 关于反编译apk出现Exception in thread "main" java.lang.ClassCastException: ....
- 2014诺贝尔生理学或医学奖揭晓
- acdream 1431 Sum vs Product
- HDU 5017 Ellipsoid (计算几何,模拟退火)
- 20141006
- 最短编辑距离 poj3356
- git 图解Git/图形化的Git参考手册
- VS2005下编译Lua源代码
- 使用INTERVAL DAY TO SECOND类型
- 实验一: VC编程工具的灵活使用
- andorid cocos2d 游戏开发入门学习经验之总结