[hdu1028]整数拆分,生成函数
题意:给一个正整数n,求n的拆分方法数(不考虑顺序)
思路:不妨考虑用1~n来构成n。用多项式表示单个数所有能构成的数,用多项式表示,就相当于卷积运算了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#include <map> #include <set> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <vector> #include <cstdio> #include <string> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define X first #define Y second #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define fillchar(a, x) memset(a, x, sizeof(a)) typedef long long ll; typedef pair< int , int > pii; typedef unsigned long long ull; #ifndef ONLINE_JUDGE void RI(vector< int >&a, int n){a.resize(n); for ( int i=0;i<n;i++) scanf ( "%d" ,&a[i]);} void RI(){} void RI( int &X){ scanf ( "%d" ,&X);} template < typename ...R> void RI( int &f,R&...r){RI(f);RI(r...);} void RI( int *p, int *q){ int d=p<q?1:-1; while (p!=q){ scanf ( "%d" ,p);p+=d;}} void print(){cout<<endl;} template < typename T> void print( const T t){cout<<t<<endl;} template < typename F, typename ...R> void print( const F f, const R...r){cout<<f<< ", " ;print(r...);} template < typename T> void print(T*p, T*q){ int d=p<q?1:-1; while (p!=q){cout<<*p<< ", " ;p+=d;}cout<<endl;} #endif template < typename T> bool umax(T&a, const T&b){ return b<=a? false :(a=b, true );} template < typename T> bool umin(T&a, const T&b){ return b>=a? false :(a=b, true );} template < typename T> void V2A(T a[], const vector<T>&b){ for ( int i=0;i<b.size();i++)a[i]=b[i];} template < typename T> void A2V(vector<T>&a, const T b[]){ for ( int i=0;i<a.size();i++)a[i]=b[i];} const double PI = acos (-1.0); const int INF = 1e9 + 7; /* -------------------------------------------------------------------------------- */ int a[123], b[123]; int main() { #ifndef ONLINE_JUDGE freopen ( "in.txt" , "r" , stdin); //freopen("out.txt", "w", stdout); #endif // ONLINE_JUDGE int n; while (cin >> n) { for ( int i = 0; i <= n; i ++) a[i] = 1; for ( int i = 2; i <= n; i ++) { fillchar(b, 0); for ( int j = 0; j <= n; j ++) { for ( int k = 0; k <= n / i; k ++) { if (j + k * i > n) break ; b[j + k * i] += a[j]; } } memcpy (a, b, sizeof (b)); } cout << a[n] << endl; } return 0; } |
[hdu1028]整数拆分,生成函数的更多相关文章
- HDU1028 (整数拆分)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 4651 Partition(整数拆分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4651 题意:给出n.求其整数拆分的方案数. i64 f[N]; void init(){ f[0 ...
- LightOJ 1336 Sigma Function(数论 整数拆分推论)
--->题意:给一个函数的定义,F(n)代表n的所有约数之和,并且给出了整数拆分公式以及F(n)的计算方法,对于一个给出的N让我们求1 - N之间有多少个数满足F(x)为偶数的情况,输出这个数. ...
- LightOJ 1341 Aladdin and the Flying Carpet(整数拆分定理)
分析:题目并不难理解,就是一些细节上的优化需要我们注意,我在没有优化前跑了2000多MS,优化了一些细节后就是400多MS了,之前还TLE了好几次. 方法:将整数拆分为质因子以后,表达为这样的形式,e ...
- 整数拆分问题_C++
一.问题背景 整数拆分,指把一个整数分解成若干个整数的和 如 3=2+1=1+1+1 共2种拆分 我们认为2+1与1+2为同一种拆分 二.定义 在整数n的拆分中,最大的拆分数为m,我们记它的方案数 ...
- Pollard-Rho大整数拆分模板
随机拆分,简直机智. 关于过程可以看http://wenku.baidu.com/link?url=JPlP8watmyGVDdjgiLpcytC0lazh4Leg3s53WIx1_Pp_Y6DJTC ...
- poj3181【完全背包+整数拆分】
题意: 给你一个数n,在给你一个数K,问你这个n用1-k的数去组合,有多少种组合方式. 思路: 背包重量就是n: 那么可以看出 1-k就是重物,价值是数值,重量是数值. 每个重物可以无限取,问题转化为 ...
- HDU 1028 Ignatius and the Princess III(母函数整数拆分)
链接:传送门 题意:一个数n有多少种拆分方法 思路:典型母函数在整数拆分上的应用 /********************************************************** ...
- LeetCode 343. 整数拆分(Integer Break) 25
343. 整数拆分 343. Integer Break 题目描述 给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化. 返回你可以获得的最大乘积. 每日一算法2019/5/2 ...
随机推荐
- Gatling脚本编写技巧篇(二)
脚本示例: import io.gatling.core.Predef._ import io.gatling.http.Predef._ import scala.concurrent.durati ...
- 微信网页授权报code been used, hints: [ req_id: XYv1Ha07042046 ]
先贴上代码: public function index() { $code = input('get.code'); $tool = new Wxtool(); if (empty($code)) ...
- php用户量剧增导致cpu100%解决办法
在php扩展里边开启opcache扩展,此扩展是解析php的缓存机制,每次解析都要消耗cpu,所以有大量的fpm进程去占用cpu,开启此扩展之后cpu就瞬间下来了,只解析第一次,往后的都使用缓存.很好 ...
- php数组gbk和utf8的相互转化
GBK转换成UFT-8用iconv()转化效率没有mb_convert_encoding()效率高eval() var_export() 把数组整体转化,如有一些特殊字符的话,可以用str_repla ...
- CCS进阶——div的宽度和高度是由什么决定的?
核心知识 文档流/普通流(Normal Flow) 内联元素的宽高(高度是由行高决定的,宽度=内容+border+marging+padding) 块级元素的宽高(高度是内部文档流元素的高度总和,宽度 ...
- 初入React源码(一)
导语 React是我接触的第二个框架,我最初开始接触的是vue,但是并没有深入的理解过vue,然后在工作过程中,我开始使用了React,现在已经觉得React会比vue更加实用,但是这只是个人观点,可 ...
- Java9新特性系列(module&maven&starter)
上篇已经深入分析了Java9中的模块化,有读者又提到了module与starter是什么关系?本篇将进行分析. 首先先回顾下module与maven/gradle的关系: module与maven/g ...
- 用Swoole4 打造高并发的PHP协程Mysql连接池
码云代码仓库:https://gitee.com/tanjiajun/MysqlPool 代码仓库:https://github.com/asbectJ/swoole4.git 前言 在写这篇文章之前 ...
- 解决Chrome插件安装时出现的“程序包无效”问题
问题原因,新版的插件头部文件的修改,导致旧版的插件包无法使用,解决方式:解压. 1.把下载后的.crx扩展名的离线Chrome插件的文件扩展名改成.zip或者.rar(如果看不到Chrome插件的扩展 ...
- Codeforce 1255 Round #601 (Div. 2) C. League of Leesins (大模拟)
Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the L ...