ACdream 1431 Sum vs Product
題目鏈接:http://115.28.76.232/problem?
pid=1431
Sum vs Product
Time Limit:?4000/2000MS (Java/Others)Memory Limit:?128000/64000KB (Java/Others) SubmitStatisticNext ProblemProblem 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
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 5Sample Output
1 3Hint
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 23Manager
mathlover SubmitStatistic這個題目事實上僅僅要枚舉下因子。暴力dfs一下就能過。。
。
//#pragma comment(linker, "/STACK:36777216") #include <functional> #include <algorithm> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <numeric> #include <cstring> #include <climits> #include <cassert> #include <complex> #include <cstdio> #include <string> #include <vector> #include <bitset> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <list> #include <set> #include <map> using namespace std; #define CLR(A,B) memset(A,B,sizeof(A)) #define CPY(A,B) memcpy(A,B,sizeof(B)) #define long long ll #define MP(A,B) make_pair(A,B) int N; long long cnt; int dfs(int now,long long sum,long long mul,int pre){if(now==N){cnt++;return 1;}for(int i=pre;i<2000;i++){int ts=sum+i,tm=mul*i;int ms=ts+N-now-1,mm=tm;if(ms==mm){cnt++;continue;}if(ms<mm) return 0;dfs(now+1,ts,tm,i);} } int main(){int F[550];for(int i=2;i<=500;i++){N=i;cnt=0;dfs(0,0,1,2);F[i]=cnt;}while(~scanf("%d",&N)) printf("%d\n",F[N]);return 0; }轉載于:https://www.cnblogs.com/llguanli/p/7047322.html
總結
以上是生活随笔為你收集整理的ACdream 1431 Sum vs Product的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【BZOJ2819】Nim 树状数组+L
- 下一篇: C语言交换两个数字的三种做法