ACdream 1431 Sum vs Product
2014-10-06 19:35
555 查看
题目链接:http://115.28.76.232/problem?pid=1431
Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)
SubmitStatisticNext
Problem
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!
The first line of the input file contains n (2 ≤ n ≤ 500)
Output one number — the number of the beautiful collections with n numbers.
The collections in the last example are: {1, 1, 1, 2, 5}, {1, 1, 1, 3, 3} and {1, 1, 2, 2, 2}.
Andrew Stankevich Contest 23
mathlover
SubmitStatistic
这个题目其实只要枚举下因子,暴力dfs一下就能过。。。
Sum vs Product
Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)SubmitStatisticNext
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
mathloverSubmitStatistic
这个题目其实只要枚举下因子,暴力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 ); return 0; }
相关文章推荐
- acdream 1431 Sum vs Product
- Sum vs Product(ACdream) —— dfs
- ACdream 1431 Sum vs Product
- Acdream 1431 Sum vs Product(dfs+剪枝)
- ACdream 1431——Sum vs Product——————【dfs+剪枝】
- acdream 1431 Sum vs Product
- ACdream 1431 Sum vs Product
- ACdream OJ 1154 Lowbit Sum
- ACDream - Sum
- ACdreamOJ 1154 Lowbit Sum (数字dp)
- ACdreamOJ 1154 Lowbit Sum (数位dp)
- 数位DP ACdream 1154 Lowbit Sum
- acdream Divide Sum
- ACdream: Sum
- ACdream 1139(Sum-逆元)
- ACdream1431-Sum vs Product
- 7、步步为营VS 2008 + .NET 3.5(7) - LINQ查询操作符之First、FirstOrDefault、Last、LastOrDefault、ElementAt、ElementAtOrDefault、Contains、Any、All、Count、LongCount、Sum、Min、Max、Average、Aggregate、Cast、DefaultIfEmpty、SequenceEqual、OfType、ToArray、ToList、ToDictionary
- ACdream 简单数论 专题
- ACdream 少了哪个妹子?( 签到)
- ACdream: ACfun