http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11445

E:   Skyscrapers
Skyscrapers  is a pencil puzzle. It’s played on a square  nxn  grid. Each cell of the grid has a 
building.  Each  row,  and  each  column,  of  the  grid  must  have  exactly  one  building  of 
height  1,  height  2, height 3,  and  so  on,  up to height  n. There  may be  numbers  at  the 
beginning and end of each row, and each column. They indicate how many buildings can 
be seen from that vantage point, where taller buildings obscure shorter buildings. In the 
game, you are given the numbers along the outside of the grid, and you must determine 
the heights of the buildings in each cell of the grid.
Consider  a  single  row  of  a  puzzle  of  size  nxn.  If  we  know  how  many  buildings  can  be 
seen from the left, and from the right, of the row, how many different ways are there of 
populating that row with buildings of heights 1..n? 
Input
There will be several  test cases in the input. Each test case consists of  three integers n a 
single line:  n  (1≤n≤5,000),  left  (1≤left≤n), and  right  (1≤right≤n), where  n  is the size of 
the row, and  left  and  right  are the number of buildings that can be seen from the left 
and right, respectively. The Input will end with a line with three 0s.
Output
For each  test case, print a single  integer indicating the number of permutations which 
satisfy  the  constraints,  modulo  1,000,000,007  (that’s  not  a  misprint,  the  last  digit  is  a 
seven). Output no extra spaces, and do not separate answers with blank lines.
Sample Input
3 2 2
4 1 2
0 0 0
Sample Output
2

2

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>using namespace std;typedef long long int LL;
const long long int MOD=1000000007;LL s[5050][5050],c[5050][5050];void init()
{for(int i=0;i<5050;i++) c[i][i]=c[i][0]=1LL;for(int i=2;i<5050;i++){for(int j=1;j<i;j++){c[i][j]=(c[i-1][j]+c[i-1][j-1])%MOD;}}s[0][0]=1;for(int i=1;i<5050;i++){for(int j=1;j<=i;j++){s[i][j]=((i-1)*s[i-1][j]%MOD+s[i-1][j-1])%MOD;}}
}void solve(int n,int left,int right)
{LL ans=0;for(int i=left;i<=n-right+1;i++){ans=(ans+((c[n-1][i-1]*s[i-1][left-1])%MOD)*s[n-i][right-1]%MOD)%MOD;}printf("%I64d\n",ans%MOD);
}int main()
{int n,left,right;init();
while(scanf("%d%d%d",&n,&left,&right)!=EOF&&n&&left&&right) solve(n,left,right);return 0;
}

SERC 2013 E Skyscrapers相关推荐

  1. 可视化数据结构的网站

    前言 无疑,数据结构与算法学习最大的难点之一就是如何在脑中形象化其抽象的逻辑步骤.而图像在很多时候能够大大帮助我们理解其对应的抽象化的东西,而如果这个图像还是我们自己一点点画出来的,那么无疑这个印象是 ...

  2. visual studio 2013 中配置OpenCV2.4.13 姿势

    首先在path中添加 "C:\OpenCV\opencv\build\x64\vc12\bin"   (地址随实际变化) 注:添加的都是*86不使用*64 在visualstudi ...

  3. SharePoint 2013 图文开发系列之代码定义列表

    在SharePoint的开发中,用Visual Studio自定义列表是经常会用到的,因为很多时候,我们并不会手动创建列表,而手动创建列表在测试服务器和正式机之间同步字段,也很麻烦,所以我们经常用代码 ...

  4. 2013年3月百度之星B题

    Sigma Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Problem Descr ...

  5. SharePoint 2013 配置开发环境,需安装VS2012插件

    SharePoint 2013已经安装好了,接下来就是配置开发环境,安装VS2012,但是,装好了以后,发现没有SharePoint 2013开发的支持,如下图: 然后,去网上查找资料,VS2012对 ...

  6. 如何用 Windows Live Writer 和 Word 2013 分别发表博客到Cnblog 和CSDN

    ps CSDN 老是505错误,放弃了 为什么会写这篇 最近写博客在 Cnblog 上面写博客, 发现图片不能复制了直接粘贴上,这对于把博客当随手笔记的人来说无疑非常痛苦.求助于博客园,他们让我用 W ...

  7. Bossie Awards 2013:最佳开源数据中心和云软件

    当Facebook 的开源计算项目(OCP)酝酿着设计更好的服务器和网络时,其他开源项目也纷纷重塑数据库,应用平台以及下一代应用程序的虚拟化层.你还不知道吧,下一代的"云"基础设施 ...

  8. Xt800、DEFY自带号码归属地更新包,更新至2013.4【数据总数278360条】

    总结了http://bbs.gfan.com/forum.php?mod=viewthread&tid=5603346&extra=page%3D1&page=1和http:/ ...

  9. infopath java包_InfoPath 2013 修补程序包 (Ipeditor x none.msp) 的描述︰ 2014 年 4 月 8,...

    修补程序信息 可以从 Microsoft 获得受支持的修复程序.然而,此修补程序仅用于解决本文中描述的问题.此修复程序仅适用于遇到本文中描述的问题的系统.此修补程序可能会接受进一步的测试.因此,如果这 ...

最新文章

  1. 图像亮度、对比度调节(伽马校正)
  2. java随机输出10计算题
  3. 自媒体时代的主流媒体不可替代
  4. Replication--查看未分发命令和预估所需时间
  5. 空战决策知识构建方法研究
  6. 【Leetcode_easy】1078. Occurrences After Bigram
  7. 将多个markdown文件发布为一个html或pdf文件的方法梳理
  8. shell awk学习3
  9. [nssl1320][jzoj cz 2108] 买装备 {dfs}
  10. 从国家大剧院古典音乐频道下载音乐
  11. 前端视频插件Video.js的基本使用
  12. 初级测试开发工程师应该学些什么
  13. Adobe Bridge使用教程:BR键盘快捷键大全
  14. 计算机实训四 表格制作素材,计算机平面设计实训(第3版 赵荣胡昌杰)课件 素材平面图像设计实训04.ppt...
  15. Accton Technology and Wedge Networks Partnership Launches Orchestrated Secure SD-WAN
  16. M1 芯片开发环境搭建全记录 ——虚拟机、 Java、Go、Python、Web
  17. 某网友嵌入式求职经验总结
  18. 使用ps制作端午海报
  19. 计算机系统要素:硬件描述语言HDL简介
  20. Bugku逆向-游戏过关

热门文章

  1. MDU某产品OMCI模块代码质量现状分析
  2. 什么是核心网?为何这么难
  3. Java TreeMap的使用
  4. 苹果手机换鸿蒙系统,鸿蒙横空出世了,换掉苹果机你愿意吗?
  5. Kotlin常见知识点和踩坑指南
  6. href=“JavaScript:;”是啥意思?
  7. 多个blockquote_无线电力BLOCKQUOTE目录
  8. 常用的安装和配置文章
  9. dependency problems
  10. 传统图像处理之颜色特征