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. JPA 入门程序及相关注解

    1. 概述 JPA(Java Persistence API):用于对象持久化的API; JPA本质上是一种ORM规范,不是ORM框架;提供了一些编程的API接口; Hibernate是实现; 1.1 ...

  2. 如何使文本溢出边界不换行强制在一行内显示?#test{width:150px;white-space:nowrap;}

    #test{width:150px;white-space:nowrap;}

  3. rest_framework 之分页器

    一  分页器--准备 1.1  基本参数 # 普通分页 from rest_framework.pagination import PageNumberPagination # 偏移分页 from r ...

  4. CentOS6.5之Zabbix3.2.2 Server安装、汉化及Agent安装

    1.安装MySQL 1.1.安装MySQL rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm yum ...

  5. ibatis打印sql

    ###显示SQL语句部分log4j.logger.com.ibatis=DEBUGlog4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUGl ...

  6. web.xml中的元素

    error-page元素包含三个子元素error-code,exception-type和location.将错误代码(Error Code)或异常(Exception)的种类对应到web应用资源路径 ...

  7. python手写bp神经网络实现人脸性别识别1.0

    写在前面:本实验用到的图片均来自google图片,侵删! 实验介绍 用python手写一个简单bp神经网络,实现人脸的性别识别.由于本人的机器配置比较差,所以无法使用网上很红的人脸大数据数据集(如lf ...

  8. 搭建virtualenv

    一.前言 1.什么是virtualenv? 在开发Python应用程序的时候,系统安装的Python3只有一个版本:3.4.所有第三方的包都会被pip安装到Python3的site-packages目 ...

  9. FileLoadTools

    /** * Created by dev013 on 9/9/14. */ var FileLoadTools = (function () { var my = {}; var htmlFile = ...

  10. 带宽、流量、CDN

    1.啥叫带宽? 1.1 带宽的概念: 在网络中的带宽往往是指一个固定的时间内,能通过的最大位数据,即数据传输率.带宽是一个计量单位,用来计量单位时间内传输的数据量的多少. 1.2 计量单位: 这个数据 ...