码迷,mamicode.com
首页 > 其他好文 > 详细

ACdream 1431 Sum vs Product

时间:2014-10-06 21:01:20      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:acm   acdream   dfs   搜索   暴力   

题目链接:http://115.28.76.232/problem?pid=1431


Sum vs Product

Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)

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

      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




这个题目其实只要枚举下因子,暴力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;
}




ACdream 1431 Sum vs Product

标签:acm   acdream   dfs   搜索   暴力   

原文地址:http://blog.csdn.net/asdfghjkl1993/article/details/39830761

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!