ACdream 1431 Sum vs Product
题目链接:http://115.28.76.232/problem?
pid=1431
Sum vs Product
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
Output
Sample Input
2 5
Sample Output
1 3
Hint
Source
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;
}
转载于:https://www.cnblogs.com/llguanli/p/7047322.html
ACdream 1431 Sum vs Product相关推荐
- 【概率证明】—— sum and product rules of probability
1. sum and product rules of probability ⎧⎩⎨p(x)=∫p(x,y)dyp(x,y)=p(x|y)p(y) \left\{ \begin{split} &am ...
- LeetCode Subarray Sum Equals K
原题链接在这里:https://leetcode.com/problems/subarray-sum-equals-k/description/ 题目: Given an array of integ ...
- MySQL中sum和count用法总结
MySQL中sum和count用法总结 1.sum 2.count 例子:要求:查询出2门及2门以上不及格者的平均成绩. 3.MySQL 分组之后如何统计记录条数 gourp by 之后的 count ...
- 使用nGraph的Intel®Xeon®上的高性能TensorFlow
使用nGraph的Intel®Xeon®上的高性能TensorFlow High-performance TensorFlow* on Intel® Xeon® Using nGraph 最近宣布了n ...
- 【C++】C++11 STL算法(七):排列操作(Permutation operations)、数值操作(Numeric operations)
排列操作(Permutation operations) 一.is_permutation 1.原型: template< class ForwardIt1, class ForwardIt2 ...
- C++向量类模板(支持实数向量与复数向量的各种运算)
2019独角兽企业重金招聘Python工程师标准>>> 头文件: /** Copyright (c) 2008-2011 Zhang Ming (M. Zhang), zmjerry ...
- VBA编程常用语句(转载)
1.Option Explicit '强制对模块内所有变量进行声明 Option Private Module '标记模块为私有,仅对同一工程中其它模块有用,在宏对话框中不显示 Option Comp ...
- 神经网络php代码,慢慢研究
为什么80%的码农都做不了架构师?>>> <?php require_once("class_neuralnetwork.php"); functio ...
- 代币转账_手把手教你从源代码开始搭建多节点以太坊私链(五)部署智能合约及代币发行...
一.安装以太坊合约编译环境 安装solc 智能合约代码的编译可以通过第三方平台或者软件.不过,为了安全起见,还是搭建自己的编译器比较好.(But be aware that if the compil ...
最新文章
- vs2015 企业版、专业版如何破解(秘钥)
- php下关于Cannot use a scalar value as an array的解决办法
- linux 下的Memcached安装和配置
- TABLES ABOUT CRM MARTETING
- Node Capital生态布局初成,部分项目差强人意
- view渐变色,透明度渐变
- 【REACT NATIVE 系列教程之十三】利用LISTVIEW与TEXTINPUT制作聊天/对话框获取组件实例常用的两种方式...
- 4 weekend110的hive入门
- 计算机类实训室建设公司,计算机专业实训室建设方案修改
- 一个大数据屌丝的一天
- QQ红包金额分配算法
- 一行脚本批量下载哔哩哔哩视频
- 全国高中生计算机联赛,全国中学生五大学科竞赛
- 计算机与管理科学的交叉与融合,计算机信息管理专业与其他专业的交叉融合论文...
- char* p 和 char p[]区别及应用
- 《绝地求生:大逃杀》百万级别数据分析项目,还有源码+数据
- JSP+MySQL校园新闻网站(5)–新闻查看功能开发
- win7 常用快捷键
- 使用Java导出数据到Excel
- 区域生长算法(附MATLAB代码实现)