K - Count the Buildings

参考:Count the Buildings

思路可以借鉴,但是代码略有问题

写的时候 re 了 9 发,然后把变量定义的顺序换了一下居然 A 了,以为这个是个骚操作,最后才发现是真的会越界,当 f+b>n+2 的时候就有可能会发生越界,而这种情况,if 判断一下就好

代码:

  1. // Created by CAD on 2019/8/17.
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. using ll=long long;
  5. const int mod=1000000007;
  6. const int maxn=2010;
  7. ll c[maxn][maxn],s[maxn][maxn];
  8. int main()
  9. {
  10. memset(s, 0, sizeof(s));
  11. memset(c, 0, sizeof(c));
  12. s[0][0]=1;
  13. for (int i=0; i<=maxn-10; ++i) c[i][0]=1;
  14. for (int i=1; i<=maxn-10; ++i)
  15. for (int j=1; j<=maxn-10; ++j){
  16. s[i][j]=(s[i-1][j-1]+(i-1)*s[i-1][j])%mod;
  17. c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
  18. }
  19. int t; scanf("%d", &t);
  20. while (t--){
  21. int n,f,b;
  22. scanf("%d%d%d",&n,&f,&b);
  23. if(f+b>n+2) cout<<0<<endl;
  24. else printf("%lld\n",(s[n-1][f+b-2]*c[f+b-2][f-1])%mod);
  25. }
  26. return 0;
  27. }

Count the Buildings的更多相关文章

  1. 【HDU 4372】 Count the Buildings (第一类斯特林数)

    Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  2. [Hdu4372] Count the Buildings

    [Hdu4372] Count the Buildings Description There are N buildings standing in a straight line in the C ...

  3. HDU4372 Count the Buildings —— 组合数 + 第一类斯特林数

    题目链接:https://vjudge.net/problem/HDU-4372 Count the Buildings Time Limit: 2000/1000 MS (Java/Others)  ...

  4. HDU 4372 Count the Buildings

    Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  5. HDU4372 Count the Buildings (+题解:斯特林数)

    题面 (笔者翻译) There are N buildings standing in a straight line in the City, numbered from 1 to N. The h ...

  6. HDU 4372 Count the Buildings:第一类Stirling数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4372 题意: 有n栋高楼横着排成一排,各自的高度为1到n的一个排列. 从左边看可以看到f栋楼,从右边看 ...

  7. HDU 4372 Count the Buildings [第一类斯特林数]

    有n(<=2000)栋楼排成一排,高度恰好是1至n且两两不同.现在从左侧看能看到f栋,从右边看能看到b栋,问有多少种可能方案. T组数据, (T<=100000) 自己只想出了用DP搞 发 ...

  8. HDU 4372 Count the Buildings——第一类斯特林数

    题目大意:n幢楼,从左边能看见f幢楼,右边能看见b幢楼 楼高是1~n的排列. 问楼的可能情况 把握看到楼的本质! 最高的一定能看见! 计数问题要向组合数学或者dp靠拢.但是这个题询问又很多,难以dp ...

  9. HDU 4372 - Count the Buildings(组合计数)

    首先想过n^3的组合方法,即f(i,j,k)=f(i-1,j,k)*(i-2)+f(i-1,j-1,k)+f(i-1,j,k-1),肯定搞不定 然后想了好久没有效果,就去逛大神博客了,结果发现需要用到 ...

随机推荐

  1. .net get set用法

    在早期学习c#的过程中,经常遇到这样的语句: public string StudentName{           get{return stuName;}           set{stuNa ...

  2. mvc布局(一)

    negut添加Optimization @System.Web.Optimization.Styles.Render( "~/Content/styles/css/font-awesome. ...

  3. 打印从1到最大的n位数(考虑大数问题)

    void Print1ToMaxOfNDigits(int n) { if(n <= 0) { return; } int * number = new int[n]; for(int i = ...

  4. 【ExtJs】获取grid选中的records

    var records = me.grid.getSelectionModel().getSelection(); //获取所有选中的行 var record =records[0]; //获取选中行 ...

  5. 初识JavaScript对象

    JavaScript对象语法.类型.属性 属性描述符(getOwnPropertyDescriptor().defineProperty()) [[Get]].[[Put]].Getter.Sette ...

  6. java字符常量

    在Java程序中经常会遇到类似于"Hello"这样地字符串,那么这种类型的字符串是Java中是如何存储,下面就说明字符串常量在内存中存储方式: Java程序在编译时会将程序中出现的 ...

  7. postman安装时提示打不开

    安装postman6.6.1时,提示打不开,如下图: 解决办法: 1.找到以下两个路径直接删除文件,注安装路径不同有可能不同 C:\Users\Administrator\AppData\Roamin ...

  8. 【Day1】2.安装运行Python

     视频地址(全部) https://edu.csdn.net/course/detail/26057 课件地址(全部) https://download.csdn.net/download/gentl ...

  9. 【转】container_of宏 分析

    在学习Linux驱动的过程中,遇到一个宏叫做container_of.该宏定义在include/linux/kernel.h中,首先来贴出它的代码: /** * container_of - cast ...

  10. 【wifi移植 1】 ap6210 wifi模块移植

    1. 编译wifi相关功能为模块,生成bcmdhd.ko:由bcmdhd.ko的模块信息可知,该模块依赖于cfg80211.ko和rfkill.ko. 2. 写脚本,开机自动加载wifi模块. 3. ...