ACdream1431-Sum vs Product
2016-10-24 22:37
211 查看
Sum vs Product
Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)Submit Statistic Next
Problem
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 numbersbeautiful 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
The first line of the input file contains n (2 ≤ n ≤ 500)
Output
Output one number — the number of the beautiful collections with n numbers.
Sample Input
2 5
Sample Output
1 3
Hint
The collections in the last example are: {1, 1, 1, 2, 5}, {1, 1, 1, 3, 3} and {1, 1, 2, 2, 2}.
Source
Andrew Stankevich Contest 23
Manager
mathlover题意:让你求1~n中任意选n个数字,保证这n个数字加和与乘积相等,问有多少种方法。
解题思路:暴力搜索,加上剪枝。从2开始枚举,乘积总是比加和的上升速度快。那么如果前m个数的和加上剩下的n-m个1的值还是小于前m个数的乘积的话,那么就不可能有让最后的和跟积相等的情况了。
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <queue> #include <stack> using namespace std; int n,sum; void dfs(int cur,int sum1,int mul,int k) { if(sum1+n-k<mul) return ; else if(sum1+n-k==mul) { sum++; return ; } for(int i=cur; i<=n; i++) dfs(i,sum1+i,mul*i,k+1); } int main() { while(~scanf("%d",&n)) { sum=0; dfs(2,0,1,0); printf("%d\n",sum); } return 0; }
相关文章推荐
- Sum vs Product(ACdream) —— dfs
- ACdream 1431 Sum vs Product
- ACdream 1431 Sum vs Product
- Acdream 1431 Sum vs Product(dfs+剪枝)
- ACdream 1431 Sum vs Product
- acdream 1431 Sum vs Product
- ACdream 1431——Sum vs Product——————【dfs+剪枝】
- acdream 1431 Sum vs Product
- #Paper Reading# SumView: A Web-based engine for summarizing product reviews and customer opinions
- Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳
- UVA10483 - The Sum Equals the Product(枚举)
- factor graph和sum product和TrueSkill相关的两个blog,相当不错
- 欧拉工程第32题:Pandigital product sum
- 【待完善】inner_product/adjacent_difference/partial_sum的用法
- VS部署中的ProductCode问题
- caffe: test code Check failed: K_ == new_K (768 vs. 1024) Input size incompatible with inner product parameters.
- SPOJ:SUM OF PRODUCT(数论)
- Codeforces Round #344 (Div. 2) E. Product Sum (三分)
- 面向目标 vs. 面向功能: 选择正确的Product Roadmap
- STL 之accumulate,adjacent_difference,inner_product,partial_sum