poj1942 Paths on a Grid 题意:给定一个长m高n$(n,m \in unsigned 32-bit)$的矩形,问有几种走法.$n=m=0$时终止. 显然的$C(m+n,n)$ 但是没有取模,n,m的范围又在unsigned int 范围内 于是有一种神奇的方法↓↓ typedef unsigned us;us C(us a,us b){//C(a,b) double cnt=1.0; while(b) cnt*=(double)(a--)/(double)(b--); re…
Paths on a Grid DescriptionImagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he's explaining that (a+b)2=a2+2ab+b2). So you decide to waste…
处理阶乘有三种办法:(1)传统意义上的直接递归,n的规模最多到20+,太小了,在本题不适用,而且非常慢(2)稍快一点的算法,就是利用log()化乘为加,n的规模虽然扩展到1000+,但是由于要用三重循环,一旦n规模变得更大,耗时就会非常之严重,时间复杂度达到O(n*m*(n-m)),本题规定了n,m用unsigned int32类型,就是说n,m的规模达到了21E以上,铁定TLE的.而且就算抛开时间不算,还存在一个致命的问题,就是精度损失随着n的增加会变得非常严重.因为n有多大,就要进行n次对数…
题目链接. 分析: #include <cstdio> #include <iostream> #include <map> #include <cstring> using namespace std; typedef unsigned long long LL; int main() { LL n, m; while(cin >> n >> m) { && m == ) break; LL s = n+m; if(…
Paths on a Grid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21297   Accepted: 5212 Description Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastere…
Paths on a Grid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 23270   Accepted: 5735 Description Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastere…
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 23008 Accepted: 5683 Description Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered ye…
Paths on a Grid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22918   Accepted: 5651 Description Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastere…
题目:HDU 3037 题意:有n个树,m个坚果,放到n个树里,可以不放完,有多少种方法. 分析: 得到组合数了. 大组合数什么费马小定理,Lucas定理都来了: 总的说,不能用二维地推了,用的却是组合数的定义. 一般来说大组合通常要取模. 那么不能边乘边模,边除边模,等式不会成立. 根据逆元,除以一个数取模 = 乘以这个数对mod的逆元. 那么式子就可以写成: 这里,我们可以预处理所有 i 对 mod 的逆元后,累乘,这样得到的就是阶乘的逆元. 然后就是求 i 对 mod 的逆元了,什么扩展欧…
typedef long long ll; /********************************** 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1<p<=1e6,p必须为素数 输入:C(n,m)%p 调用lucas(n,m,p) 复杂度:min(m,p)*log(m) ***********************************/ //ax + by = gcd(a,b) //传入固定值a,b.放回 d=gcd(a,b), x , y…