博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
acdream 1431 Sum vs Product
阅读量:6858 次
发布时间:2019-06-26

本文共 1768 字,大约阅读时间需要 5 分钟。

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

25

Sample Output

13

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

题解及代码:

       通过打表前几项我们会发现构成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 
#include
#include
#include
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;}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

你可能感兴趣的文章
AtomicLong可以被原子地读取和写入的底层long值的操作
查看>>
Android studio 将 Module 打包成 Jar 包
查看>>
coffee script
查看>>
正则表达式大全
查看>>
SVN switch 用法详解
查看>>
Javascript文件下载顺序问题
查看>>
程序员第一定律:关于技能与收入
查看>>
网络通讯合并数据发送的重要性和实现原理
查看>>
Jquery getJSON 实现跨域请求 --- callback
查看>>
<转载>构造函数与拷贝构造函数
查看>>
[转]K近邻算法
查看>>
表单元素01
查看>>
React Native项目Xcode打包发布iOS问题
查看>>
JPress v1.0-rc2 发布,新增微信小程序 SDK
查看>>
Confluence 6 为搜索引擎隐藏外部链接
查看>>
Python Mysql 数据库操作
查看>>
iOS Autolayout 介绍 2 Interface Builder 技巧
查看>>
打卡加虐狗
查看>>
Springboot + swagger2 通过实体对象封装形式上传视频或者图片问题解决
查看>>
Confluence 5 中如何快速创建一个 JIRA Ticket
查看>>