2017-08-10 21:10:08

writer:pprp

//TLE
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm> using namespace std; const int INF = 0x3f3f3f3f;
typedef long long ll;
const int maxn = ; ll dp[maxn][maxn]; const int mod = 1e9 + ; void S1()
{
for(int i = ; i <= ; i++)
{
dp[i][] = ;
dp[i][i] = ;
for(int j = ; j < i ; j++)
dp[i][j] = (i - ) * dp[i-][j] + dp[i-][j-];
}
} //a^b%m 快速幂
int quick_power_mod(int a, int b, int m)
{
int result = ;
int base = a;
while(b > )
{
if(b& == )//如果b是奇数
{
result = (result * base) % m;
}
base = (base * base)%m;
b>>=;
}
return result;
} //组合数取模 C(a,b)%p
ll composition(ll a, ll b, int p)
{
if(a < b)
return ;
if(a == b)
return ;
if(b > a - b) b = a - b; int ans = , ca = , cb = ;
for(ll i = ; i < b; i++)
{
ca = (ca * (a - i))%p;
cb = (cb * (b - i))%p;
} ans = (ca * quick_power_mod(cb,p - , p)) % p;
return ans;
} ll lucas(ll n, ll m, ll p)
{
ll ans = ;
while(n && m && ans)
{
ans = (ans * composition(n%p, m%p, p))%p;
n /= p;
m /= p;
}
return ans;
} int main()
{
S1();
int T;
cin >> T;
int N, F, B; while(T--)
{
cin >> N >> F >> B;
cout << dp[N-][F+B-]*composition(F+B-,F-,mod) <<endl;
}
return ;
}

标解:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm> using namespace std; const int INF = 0x3f3f3f3f;
typedef long long ll;
const int maxn = ; ll dps[maxn][maxn];
ll dpc[maxn][maxn]; const ll mod = 1e9 + ; void init()
{
for(int i = ; i < maxn ; i++)
{
dpc[i][] = dpc[i][i] = dps[i][i] = ;
for(int j = ; j < i ; j++)
{
dpc[i][j] = (dpc[i-][j-]+dpc[i-][j])%mod;
dps[i][j] = ((i-)*dps[i-][j])%mod + dps[i-][j-]%mod;
}
}
} int main()
{
int T;
cin >> T;
long long N, F, B;
init(); while(T--)
{
cin >> N >> F >> B;
cout << dps[N-][F+B-]*dpc[F+B-][F-]%mod <<endl;
}
return ;
}

标解中组合数是用杨辉三角求解的

杨辉三角dp法

dp[i][j]=dp[i-1][j-1]+dp[i-1][j]

O(n^2)~O(1)

counting the buildings - 第一类斯特灵数的更多相关文章

  1. HDU 3625 Examining the Rooms【第一类斯特灵数】

    <题目链接> <转载于 >>> > 题目大意:有n个锁着的房间和对应n扇门的n把钥匙,每个房间内有一把钥匙.你可以破坏一扇门,取出其中的钥匙,然后用取出钥匙打 ...

  2. Examining the Rooms - 第一类斯特灵数

    ---恢复内容开始--- 2017-08-10 20:32:37 writer:pprp 题意如下: Recently in Teddy's hometown there is a competiti ...

  3. cf932E. Team Work(第二类斯特灵数 组合数)

    题意 题目链接 Sol 这篇题解写的非常详细 首先要知道第二类斯特灵数的一个性质 \[m^n = \sum_{i = 0}^m C_{n}^i S(n, i) i!\] 证明可以考虑组合意义:\(m^ ...

  4. 斯特灵数 (Stirling数)

    @维基百科 在组合数学,Stirling数可指两类数,都是由18世纪数学家James Stirling提出的. 第一类 s(4,2)=11 第一类Stirling数是有正负的,其绝对值是个元素的项目分 ...

  5. Examining the Rooms(dp,斯特灵数)

    Examining the Rooms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. Rank - 第二类斯特灵数

    2017-08-10 20:32:37 writer:pprp 题意如下: Recently in Teddy's hometown there is a competition named &quo ...

  7. 斯特灵(Stirling)数

    http://zh.wikipedia.org/wiki/%E6%96%AF%E7%89%B9%E7%81%B5%E6%95%B0 第一类:n个元素分成k个非空循环排列(环)的方法总数 递推式:s(n ...

  8. 7-n!的位数(斯特灵公式)

    http://acm.hdu.edu.cn/showproblem.php?pid=1018 Big NumberTime Limit: 2000/1000 MS (Java/Others) Memo ...

  9. 弗罗贝尼乌斯範数(Frobenius norm)

    弗罗贝尼乌斯範数 对 p = 2,这称为弗罗贝尼乌斯範数(Frobenius norm)或希尔伯特-施密特範数( Hilbert–Schmidt norm),不过后面这个术语通常只用于希尔伯特空间.这 ...

随机推荐

  1. webservice接口问题:Payload: No message body writer has been found for class domain, ContentType: application/xml

    当在使用cxf-rs的webservice的时候,有时候在传输数据,会发生这种错误 错误代码: Response-Code: 500 Content-Type: text/plain Headers: ...

  2. Python(并发编程进程)

    并发编程 二.多进程 要让Python程序实现多进程(multiprocessing),我们先了解操作系统的相关知识. Unix/Linux操作系统提供了一个fork()系统调用,它非常特殊.普通的函 ...

  3. Purpose of ContextLoaderListener in Spring

    The ApplicationContext is where your Spring beans live. The purpose of the ContextLoaderListener is ...

  4. air游戏接入小米支付sdk

    小米支付sdk要求在Application.onCreate中进行初始化 为了这个初始化搞了半天,最终搞定了.今天将更改的步骤记录下了. 1. 创建ANE.ANE的创建就不罗嗦了,这里须要注意一点,这 ...

  5. instanceof判断参数是否是给定的类型

    if(ofj instanceof CLOB) {//判断ofj是否是CLOB类型,如果是则把CLOB内容解析出来,放入TZNR字段中并返回 CLOB ft = (CLOB)ofj; String c ...

  6. PHP生成名片、网址二维码

    PHP生成名片.网址二维码 php生成名片(vcard)二维码: <?php$vname = 'test';  $vtel = '13800000000';  generateQRfromGoo ...

  7. for…else和while…else

    当while语句配备else子句时,如果while子句内嵌的循环体在整个循环过程中没有执行break语句(循环体中没有break语句,或者循环体中有break语句但是始终未执行),那么循环过程结束后, ...

  8. 利用trigger同步Oracle数据库

    oracle不同数据库之间进行同步数据时,可以用触发器来实现,但需要数据库A访问数据库B,那么可以通过创建数据连接来实现,代码如下: CREATE DATABASE LINK dblink_test ...

  9. 自适应Simpson公式

    参考刘汝佳<算法指南>P163 #include<cstdio> #include<cmath> double a; double F(double x){ +*a ...

  10. 如何释放linux cache占用的内存

    [root@prd-fygl-app-01 ~]# free -m             total       used       free     shared    buffers     ...