题目:http://acm.hdu.edu.cn/showproblem.php?pid=4651 参考:https://blog.csdn.net/u013007900/article/details/42365823 https://blog.csdn.net/visit_world/article/details/52734860 好像这样复杂度就是 \( O(n\sqrt{n} \) 的了. #include<cstdio> #include<cstring> #inclu…
Integer Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22    Accepted Submission(s): 15 Problem Description Given n, k, calculate the number of different (unordered) partitions of n s…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4658 题意:给出n.k.求n的拆分方案数.要求拆分中每个数不超过k. i64 f[N]; void init(){    f[0]=f[1]=1; f[2]=2;    int i,j,k,t;    for(i=3;i<N;i++) for(j=1;;j++)    {        FOR0(k,2)        {            if(!k) t=(3*j*j-j)/2;     …
五角数定理!!可以参考这个http://www.cnblogs.com/xin-hua/p/3242428.html  代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<string> #include<vector> #define ll __int64 #de…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4772 题解:https://blog.csdn.net/Dream_Lolita/article/details/82314788 关于 \( g[p^t] \) 的值是多少,提供自己的见解: 首先,和 \( p^t \) 互质的数有 \( p^{t-1} \) 段,每段有 \( p-1 \) 个,模 p 等于 1 ~ p-1 . 那么和 \( p^t \) 做 gcd 的就是 \( p^…
hdu 4658 Integer Partition 题意 n分拆成若干个正整数的和,每个正整数出现小于k次,分拆方案有多少.(t<=100,n<=1e5) 题解 之前写过一篇Partition Numbers的计算,后面补充了hdu 4651的做法.就是利用五边形数定理. 这题加强了限制条件. n的无序分拆数的生成函数: \(\sum_{i=1}^{\infty}B(i)x^i=(1+x+x^2+..)(1+x^2+x^4+..)-=\frac {1}{\prod_{i=1}^{\infty…
题意:把一个整数N(1 <= N <= 100000)拆分不超过N的正整数相加,有多少种拆法. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4651 ——>>好经典的问题,但数好大,比赛卡住了... 原来,这个问题有个公式计算: q[i]为第i个广义五边形数. #include <cstdio> using namespace std; const int maxn = 100000; const int mod = 1…
下面内容摘自维基百科: 五边形数定理[编辑] 五边形数定理是一个由欧拉发现的数学定理,描写叙述欧拉函数展开式的特性[1] [2].欧拉函数的展开式例如以下: 亦即 欧拉函数展开后,有些次方项被消去,仅仅留下次方项为1, 2, 5, 7, 12, ...的项次,留下来的次方恰为广义五边形数. 当中符号为- - + + - - + + ..... 若将上式视为幂级数,其收敛半径为1,只是若仅仅是当作形式幂级数(formal power series)来考虑,就不会考虑其收敛半径. 和切割函数的关系…
Integer Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 524 Accepted Submission(s): 238 Problem Description Given n, k, calculate the number of different (unordered) partitions of n such…
HDU 4651 Partition Problem : n的整数划分方案数.(n <= 100008) Solution : 参考资料: 五角数 欧拉函数 五边形数定理 整数划分 一份详细的题解 欧拉函数的定义如下: \[\phi(q) =\prod\limits_{n=1}^{\infty}(1-q^n) \] 五边形定理对欧拉函数展开如下: \[\phi(q) = \sum_{n = 0}^{n = \infty}(-1)^nq^{\frac{3n^2\pm n}{2}}\] 其中 \(\…
println("--------------------"+data.rdd.getNumPartitions) // 获取DF中partition的数目 val partitions = data.rdd.glom().collect() // 获取所有data下所有的partition,返回一个partition的集合 for(part <- partitions){ println(part.getClass.getName + "::::::::"…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4651 题意:给出n.求其整数拆分的方案数. i64 f[N]; void init(){    f[0]=f[1]=1; f[2]=2;    int i,j,k,t;    for(i=3;i<N;i++) for(j=1;;j++)    {        FOR0(k,2)        {            if(!k) t=(3*j*j-j)/2;            else t=…
Partition Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 462    Accepted Submission(s): 262 Problem Description How many ways can the numbers 1 to 15 be added together to make 15? The technica…
Partition Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 842    Accepted Submission(s): 478 Problem Description How many ways can the numbers 1 to 15 be added together to make 15? The technical…
别人的解题报告: http://blog.csdn.net/zstu_zlj/article/details/9796087 我的代码: #include <cstdio> #define N 100020 ; int p[N]; void Partition() { p[] =; ; n <= 1e5; ++n) { ; ; while(true) { *k-)/; ) break; p[n] = (p[n]+fac*p[t])%mod; ) p[n] = (p[n]+fac*p[t-…
定理详见维基百科....http://zh.wikipedia.org/wiki/%E4%BA%94%E9%82%8A%E5%BD%A2%E6%95%B8%E5%AE%9A%E7%90%86 代码如下: #include <cstdio> #include <cstring> #include <algorithm> #define LL long long #define INF 0x7fffffff #define MOD 1000000007 #define M…
Triangle Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 304    Accepted Submission(s): 170Special Judge Problem Description Chiaki has 3n points p1,p2,…,p3n. It is guaranteed that n…
题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=530 (格式有一点点问题,直接粘下来吧) 题目意思:给出 n 和 k,问能否构造 k-1个不同的数使得这 k-1 个数(每个数都为正整数)的和等于一个数的平方,且 k 个数(都为正整数)的和等于 n. 错了差不多十多次,终于要看别人思路了....... 为了将问题简化,且保证 k-1 个数都是不同的,我们从自然数1,2,...,k-2 构…
题目链接:Vjudge 传送门 相当于把nnn个点分隔为若干块,求所有方案中大小为kkk的块数量 我们把大小为kkk的块,即使在同一种分隔方案中的块 单独考虑,它可能出现的位置是在nnn个点的首.尾.中 出现在首尾时,有222种情况,此时剩下的点有(n−k−1)(n-k-1)(n−k−1)个间隔,每个间隔可分可不分,所以方案数为2⋅2(n−k−1)2\cdot 2^{(n-k-1)}2⋅2(n−k−1) 出现在中间时,有(n−k−1)(n-k-1)(n−k−1)种情况,此时剩下的点有(n−k−2…
Problem Description Oneof the first users of BIT's new supercomputer was Chip Diller. He extended hisexploration of powers of 3 to go from 0 to 333 and he explored taking varioussums of those numbers.  ``This supercomputer is great,'' remarked Chip.…
本文是整数划分的第二节,主要介绍整数划分的一些性质. 一 先来弥补一下上一篇文章的遗留问题:要求我们所取的 (n=m1+m2+...+mi )中  m1 m2 ... mi连续,比如5=1+4就不符合要求了.这个时候的整数划分怎么操作呢? 这个问题的答案是这样的: 假设 n = r + (r + 1) + · · · + (r + k) ,我们需要找到所有的 r,这样我们就能获得划分数目了. 对上式进一步合并我们获得了 (2r + k)(k + 1) = 2n. 我们知道等式右面为一个偶数,而左…
话说今天百度面试,可能是由于我表现的不太好,面试官显得有点不耐烦,说话的语气也很具有嘲讽的意思,搞得我有点不爽.Whatever,面试中有问到整数划分问题,回答这个问题过程中被面试官搞的不胜其烦,最后也给出了其动态规划的算法,但是显然,醉翁之意不在动态规划而在于生成函数(generating function).下面开始吧:   参考:http://www.skymoon.biz/?p=192  (问题定义以及动态规划)          http://www.artofproblemsolvi…
Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1249    Accepted Submission(s): 408 Problem Description There are N buildings standing in a straight line in the City, numbere…
Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next few days. As a crazy fan of Harry Potter, you will go to the cinema and have the first sight, won’t you? Suppose the cinema only has one tic…
Sightseeing Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1023    Accepted Submission(s): 444 Problem Description Tour operator Your Personal Holiday organises guided bus trips across the Ben…
http://acm.hdu.edu.cn/showproblem.php?pid=1240 开始没仔细看题,看懂了发现就是一个裸的bfs,注意坐标是三维的,然后每次可以扩展出6个方向. 第一维代表在第几层.后两维代表行和列. #include <cstdio> #include <cstring> #include <queue> using namespace std; struct point { int x,y,z,step; bool operator <…
http://acm.hdu.edu.cn/showproblem.php?pid=1242 感觉题目没有表述清楚,angel的朋友应该不一定只有一个,那么正解就是a去搜索r,再用普通的bfs就能过了. 但是别人说要用优先队列来保证时间最优,我倒是没明白,步数最优跟时间最优不是等价的吗?就算士兵要花费额外时间,可是既然先到了目标点那时间不也一定是最小的? 当然用优先队列+ a去搜索r是最稳妥的. #include <cstdio> #include <cstring> #inclu…
HDU 1068 :题目链接 题意:一些男孩和女孩,给出一些人物关系,然后问能找到最多有多少个人都互不认识. 转换一下:就是大家都不认识的人,即最大独立集合 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <math.h> #define init(a) memset(a,…
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4099 这个题目就是一个坑或. 题意:给你不超过40的一串数字,问你这串数字是Fibonacci多少的开头几位数字,如果不存在则输出-1. 题解:明明说好的不超过40,但是在建字典数的时候不加i<41就超内存了,杭电你是想咋地,害的我比较好多人的代码,一点一点试出来的. AC代码: #include <iostream> #include <cstdio> #include <…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3625 题意: 有n个房间,每个房间里放着一把钥匙,对应能开1到n号房间的门. 除了1号门,你可以踹开任意一扇门(不用钥匙),但你最多只能踹k次. 问你能将所有门打开的概率. 题解: · P(打开所有门) = 能打开所有门的钥匙放置情况数 / 钥匙放置的总情况数 · 钥匙放置的总情况数 = n! 那么考虑下能打开所有门的钥匙放置情况数... 由于每个房间里有且只有一把钥匙,所以如果将每个房间连向房间内…