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. 全面介绍Windows内存管理机制及C++内存分配实例(四):内存映射文件

    本文背景: 在编程中,很多Windows或C++的内存函数不知道有什么区别,更别谈有效使用:根本的原因是,没有清楚的理解操作系统的内存管理机制,本文企图通过简单的总结描述,结合实例来阐明这个机制. 本 ...

  2. Flask之视图函数

    视图示例 @app.route('/hello') def hello(): return 'Hello World' if __name__ == '__main__': app.run() 特殊的 ...

  3. 如何制作一款HTML5 RPG游戏引擎——第五篇,人物&人物特效

    上一次,我们实现了对话类,今天就来做一个游戏中必不可少的——人物类. 当然,你完全是可以自己写一个人物类,但是为了方便起见,还是决定把人物类封装到这个引擎里. 为了使这个类更有意义,我还给人物类加了几 ...

  4. Jmeter(五)mysql的增删改查

    一.导入jdbc的jar包,因为jmeter本身不能直接连接mysql,所以需要导入第三方的jar包,来连接mysql jar包下载地址:https://pan.baidu.com/s/17qQZPF ...

  5. 避免SSH连接因超时闲置断开

    用SSH过程连接电脑时,经常遇到长时间不操作而被服务器踢出的情况,常见的提示如: Write failed: Broken pipe 这是因为如果有一段时间在SSH连接上无数据传输,连接就会断开.解决 ...

  6. dbms_advisor 手动生成段顾问建议!

    执行包需要dbms_advisor权限: sys@ORCL> grant advisor to u1; 授权成功. 创建段顾问任务,指定create_task的advisor_name参数为“段 ...

  7. vim高亮显示文本

    行列高亮设置 • 行高亮 " 设置高亮行的颜色,ctermbg设定背景色,ctermfg设定前景色 set cursorline hi CursorLine cterm=NONE cterm ...

  8. 工作笔记——js与文件上传下载

    1 js判断上传文件的后缀名,文件大小 //判断照片大小 function getPhotoSize(obj){ photoExt=obj.value.substr(obj.value.lastInd ...

  9. mac shell

    查看所有shell:cat /etc/shells 查看当前正在使用的shell:echo $SHELL 切换shell:chsh -s /bin/zsh

  10. 转:centos彻底删除文件夹、文件命令

    转自:http://www.cnblogs.com/kluan/p/4458296.html centos彻底删除文件夹.文件命令(centos 新建.删除.移动.复制等命令: 1.新建文件夹 mkd ...