HDU 3037 Saving Beans (Lucas法则)】的更多相关文章

Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4315    Accepted Submission(s): 1687 Problem Description Although winter is far away, squirrels have to work day and night to save be…
解题思路: 直接求C(n+m , m) % p , 由于n , m ,p都非常大,所以要用Lucas定理来解决大组合数取模的问题. #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string&g…
hdu 3037 Saving Beans 题目大意:n个数,和不大于m的情况,结果模掉p,p保证为素数. 解题思路:隔板法,C(nn+m)多选的一块保证了n个数的和小于等于m.可是n,m非常大,所以用到Lucas定理. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ll n, m, p; ll qPow (ll a…
Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2079    Accepted Submission(s): 748 Problem Description Although winter is far away, squirrels have to work day and night to save bea…
Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8258    Accepted Submission(s): 3302 Problem Description Although winter is far away, squirrels have to work day and night to save be…
Saving Beans Time Limit: 3000 MS Memory Limit: 32768 K Problem Description Although winter is far away, squirrels have to work day and night to save beans. They need plenty of food to get through those long cold days. After some time the squirrel fam…
主题链接:pid=3037">http://acm.hdu.edu.cn/showproblem.php?pid=3037 推出公式为C(n + m, m) % p. 用Lucas定理求大组合数取模的值 代码: #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; int t; long long n, m, p; long long pow(lo…
Problem Description Although winter is far away, squirrels have to work day and night to save beans. They need plenty of food to get through those long cold days. After some time the squirrel family thinks that they have to solve a problem. They supp…
题意:问用不超过 m 颗种子放到 n 棵树中,有多少种方法. 析:题意可以转化为 x1 + x2 + .. + xn = m,有多少种解,然后运用组合的知识就能得到答案就是 C(n+m, m). 然后就求这个值,直接求肯定不好求,所以我们可以运用Lucas定理,来分解这个组合数,也就是Lucas(n,m,p)=C(n%p,m%p)* Lucas(n/p,m/p,p). 然后再根据费马小定理就能做了. 代码如下: 第一种: #pragma comment(linker, "/STACK:10240…
Saving Beans Time Limit: 3000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 303764-bit integer IO format: %I64d      Java class name: Main   Although winter is far away, squirrels have to work day and night to save beans. T…
如果您有n+1树,文章n+1埋不足一棵树m种子,法国隔C[n+m][m] 大量的组合,以取mod使用Lucas定理: Lucas(n,m,p) = C[n%p][m%p] × Lucas(n/p,m/p,p) ; Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2314    Accepted Submissi…
Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5769    Accepted Submission(s): 2316 Problem Description Although winter is far away, squirrels have to work day and night to save b…
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; int jc[100003]; int p; int ipow(int x, int b) { ll t = 1, w = x;…
acm.hdu.edu.cn/showproblem.php?pid=3037 [题意] m个松果,n棵树 求把最多m个松果分配到最多n棵树的方案数 方案数有可能很大,模素数p 1 <= n, m <= 1000000000, 1 < p < 100000 [思路] 答案为C(n+m,m)%p 对于C(n, m) mod p.这里的n,m,p(p为素数)都很大的情况.就不能再用C(n, m) = C(n - 1,m) + C(n - 1, m - 1)的公式递推了.这里用到Luca…
题目链接 题目大意,N颗树上取不超过M个果子,求总方案个数模P的值,P是质数且不超过10w,N,M不超过1e9: 在这里树是被认为不同的,也就是将k(0<=k<=M)个小球放入N个不同的盒子的方案个数,这是一个经典的问题--> <   n个相同球放入m个不同盒,盒子可空,方案数C(n+m-1,m-1)  > 所以答案就是求 SUM{C(N+i-1,i) | 0<=i<=M},这个式子可以利用 C(n,k)=C(n-1,k)+C(n-1,k-1)来化简,因为第一项C…
hdu3037 Saving Beans 题意:n个不同的盒子,每个盒子里放一些球(可不放),总球数<=m,求方案数. $1<=n,m<=1e9,1<p<1e5,p∈prime$ 卢卡斯(Lucas)定理(计算组合数 防爆精度) $lucas(n,m,p)=lucas(n/p,m/p,p)*C(n\%p,m\%p,p)$ $lucas(n,0,p)=1$ 老套路,插板法. 设m个球都要放,多一个盒子轻松解决. 根据插板法得方案数$=C(n+m,n)$ 跑一遍Lucas. en…
Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Although winter is far away, squirrels have to work day and night to save beans. They need plenty of food to get through those long c…
Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4153    Accepted Submission(s): 1607 Problem Description Although winter is far away, squirrels have to work day and night to save be…
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩dp+广搜 使用dp[x][y][key][s]来记录孙悟空的坐标(x,y).当前获取到的钥匙key和打死的蛇s.由于钥匙具有先后顺序,因此在钥匙维度中只需开辟大小为10的长度来保存当前获取的最大编号的钥匙即可.蛇没有先后顺序,其中s的二进制的第i位等于1表示打死了该蛇,否则表示没打死.然后进行广度…
Problem Description Although winter is far away, squirrels have to work day and night to save beans. They need plenty of food to get through those long cold days. After some time the squirrel family thinks that they have to solve a problem. They supp…
#include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<vector> #define MAXN 100000+10 #define ll long long #define pb push_back #define ft first #define sc second #define mp make_pair #define pil pa…
排列组合 啊……这题是要求c(n-1,0)+c(n,1)+c(n+1,2)+......+c(n+m-1,m) 这个玩意……其实就等于c(n+m,m) 好吧然后就是模P……Lucas大法好= = 我SB地去预处理<P的所有fac和inv了……果断TLE 事实上Lucas时对于<P的部分直接暴力算就好了 //HDOJ 3037 #include<cstdio> #include<cstdlib> #include<cstring> #include<io…
题目大概问小于等于m个的物品放到n个地方有几种方法. 即解这个n元一次方程的非负整数解的个数$x_1+x_2+x_3+\dots+x_n=y$,其中0<=y<=m. 这个方程的非负整数解个数是个经典问题,可以+1转化正整数解的个数用插板法解决:$C_{y+n-1}^{n-1}=C_{y+n-1}^y$. 而0<=y<=m,最后的结果就是—— $$\sum_{i=0}^m C_{i+n-1}^i$$ $$C_{n-1}^0+C_{n}^1+C_{n+1}^2+\dots+C_{n-1…
对于很大的组合数不能用C(n, m) = C(n - 1, m) + C(n-1, m -1)来求,这里就用到Lucas定理. 模板题: hdu3037:模板如下: #include <cstdio> using namespace std; ; typedef long long ll; ll F[maxn]; //求1-p所有的阶乘模上p void init(ll p) { F[] = ; ; i <= p; i++) F[i] = F[i - ] * i % p; } //求逆元…
[基本解题思路] 将n个相同的元素排成一行,n个元素之间出现了(n-1)个空档,现在我们用(m-1)个“档板”插入(n-1)个空档中,就把n个元素隔成有序的m份,每个组依次按组序号分到对应位置的几个元素(可能是1个.2个.3个.4个.….),这样不同的插入办法就对应着n个相同的元素分到m组的一种分法,这种借助于这样的虚拟“档板”分配元素的方法称之为插板法. [基本题型的变形(一)] 题型:有n个相同的元素,要求分到m组中,问有多少种不同的分法? 解题思路:这种问题是允许有些组中分到的元素为“0”…
组合数学推推推最后,推得要求C(n+m,m)%p 其中n,m小于10^9,p小于1^5 用Lucas定理求(Lucas定理求nm较大时的组合数) 因为p数据较小可以直接阶乘打表求逆元 求逆元时,由费马小定理知道p为素数时,a^p-1=1modp可以写成a*a^p-2=1modp 所以a的逆元就是a^p-2, 可以求组合数C(n,m)%p中除法取模,将其转化为乘法取模 即    n!/(m!*(n-m)!)=n!*(m!*(n-m)!)^p-2 求C(n+m,m). n,m<=1000,二维数组递…
先说下lucas定理 1)Lucas定理:p为素数,则有: (2)证明: n=(ak...a2,a1,a0)p = (ak...a2,a1)p*p + a0 =  [n/p]*p+a0 (注意 这里()p表示的是p进制数),m=[m/p]*p+b0其次,我们知道,对任意质数p有(1+x)^p=1+(x^p)(mod p) .我们只要证明这个式子:C(n,m)=C([n/p],[m/p]) * C(a0,b0)(mod p),那么就可以用归纳法证明整个定理.对于模p而言,我们有下面的式子成立: 上…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess claire_ was jailed in a maze by Grand Demon Monster(GDM) teoy.Out of anger, little Prince ykwd decides to break into the maze to rescue his lovely Prince…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5446 Unknown Treasure 问题描述 On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician entered the cave because it is there. Somewhere…
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3242    Accepted Submission(s): 1127 Problem Description <Journey to the West>…