https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2124

这道题可以用递推做,但是没有必要

首先说长度为L

假设R的个数为x,O的个数为y,那么x+y=L而且x-y=4

当L为奇数和小于4的时候肯定不可以

由于O不能相邻 可以假设O 的数目和R一样多,交叉排放。然后从这些O中

去掉4个

1,R开头的情况 C(x,4)

2,O开头的情况C(x-1,4)

然后两种情况相加即可

代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue> #define ll long long
using namespace std; ll C(int n,int m)
{
ll tmp=1;
for(int i=0;i<m;++i)
tmp=tmp*(n-i);
for(int i=1;i<=m;++i)
tmp=tmp/i;
return tmp;
}
int main()
{
//freopen("data.in","r",stdin);
int ca=0;
int n;
while(cin>>n)
{
++ca;
if(!n) break;
cout<<"Case "<<ca<<": ";
if(n<4||n%2==1)
cout<<"0"<<endl;
else
cout<<C((n+4)/2,4)+C((n+4)/2-1,4)<<endl;
}
return 0;
}

  

LA 4123 - Glenbow Museum的更多相关文章

  1. UVALive 4123 Glenbow Museum (组合数学)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 易得,当n为奇数或者n<3时,答案为0,否则该序列中必定有(n+4)/2个R ...

  2. LA 4123 (计数 递推) Glenbow Museum

    题意: 这种所有边都是垂直或水平的多边形,可以用一个字符串来表示,一个270°的内角记作O,一个90°的内角记作R. 如果多边形内存在一个点,能看到该多边形所有的点,则这个多边形对应的序列是合法的.这 ...

  3. UVa1073 Glenbow Museum

    可以把R看成顺时针转90°,O看成逆时针转270° 设R有x个,则180*(n-2)=90*x+270*(n-x) 解得R有(n+4)/2个 O有(n-4)/2个 所以n<4或者n是奇数时无解. ...

  4. leggere la nostra recensione del primo e del secondo

    La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...

  5. Le lié à la légèreté semblait être et donc plus simple

    Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...

  6. Mac Pro 使用 ll、la、l等ls的别名命令

    在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...

  7. Linux中的动态库和静态库(.a/.la/.so/.o)

    Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...

  8. Mac OS使用ll、la、l等ls的别名命令

    在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -al ...

  9. UVALive - 2965 Jurassic Remains (LA)

    Jurassic Remains Time Limit: 18000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Sub ...

随机推荐

  1. JavaWeb学习计划

    1 HTML2 CSS3 JavaScript4 XML5 Tomcat6 Servlet7 HTTP8 Cookie Session9 JSP10 JSTL11 MySQL12 JDBC13 过滤器 ...

  2. shell脚本中获取本机ip地址的方法

    ipaddr='172.0.0.1' ipaddr=$(ip addr | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/ ...

  3. ManyToMany关联方式----

    http://blog.csdn.net/sinat_18882775/article/details/51171427 好的博客 系列文章总结

  4. Java的动态绑定

    看这段代码 Father father = new Son(); 父类引用指向子类对象,这是java的多态特性,有多态引到动态绑定,如何引入呢,看这个代码: class Father{ private ...

  5. drush cc all 报错

    请看好 指明了Module文件的行数 报错一定要多看看哦.

  6. this和call

    function foo(x){ console.log(x);} foo.call(this,'abc');console.log(this); ---- abc

  7. 可视化工具之 IGV 使用方法

    整合基因组浏览器(IGV)是一种高性能的可视化工具,用来交互式地探索大型综合基因组数据.它支持各种数据类型,包括array-based的和下一代测序的数据和基因注释. IGV这个工具很牛,发了NB: ...

  8. 项目解析- JspLibrary - part3

    CRUD read: String sql = "select b.*,c.name as bookcaseName,p.pubname as publishing,t.typename f ...

  9. 串行通讯之.NET SerialPort异步写数据

    目录 第1章说明    2 1 为什么需要异步写数据?    2 2 异步写数据的代码    2 3 源代码    4 第1章说明 1 为什么需要异步写数据? 如下图所示,以波特率300打开一个串口. ...

  10. java 集合(Set2)

    TreeSet: 1.向TreeSet添加元素时 如果元素具有自然特性,那么就按照元素的自然顺序的特点进行排序储存. 如果不具备,就要实现Compareable接口中的compareTo() 方法. ...