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. poj1474Video Surveillance(半平面交)

    链接 半平面交的模板题,判断有没有核.: 注意一下最后的核可能为一条线,面积也是为0的,但却是有的. #include<iostream> #include <stdio.h> ...

  2. Java中HashMap案例

    package ch8; import java.util.*; /** * Created by Jiqing on 2016/11/27. */ public class MapTest { pu ...

  3. android 主线程和子线程之间的消息传递

    从主线程发送消息到子线程(准确地说应该是非UI线程)  package com.zhuozhuo; import android.app.Activity; import android.os.Bun ...

  4. centos7 php7 安装composer时Failed to decode zlib stream解决办法

    1 下载安装脚本 php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 2 运行安装脚 ...

  5. 转:最小区间:k个有序的数组,找到最小区间使k个数组中每个数组至少有一个数在区间中

    转:http://www.itmian4.com/thread-6504-1-1.html 最小区间原题 k个有序的数组,找到最小的区间范围使得这k个数组中,每个数组至少有一个数字在这个区间范围内.比 ...

  6. 全局变量报错:UnboundLocalError: local variable 'l' referenced before assignment

    总结: 内部函数,不修改全局变量可以访问全局变量 内部函数,修改同名全局变量,则python会认为它是一个局部变量 在内部函数修改同名全局变量之前调用变量名称(如print sum),则引发Unbou ...

  7. 最大似然估计(Maximum Likelihood,ML)

    先不要想其他的,首先要在大脑里形成概念! 最大似然估计是什么意思?呵呵,完全不懂字面意思,似然是个啥啊?其实似然是likelihood的文言翻译,就是可能性的意思,所以Maximum Likeliho ...

  8. Unity5中叹为观止的实时GI效果

    http://www.manew.com/thread-43970-1-1.html 今天为大家分享unity与Alex Lovett共同使用unity5制作的Shrine Arch-viz Demo ...

  9. Java集合框架:HashMap

    转载: Java集合框架:HashMap Java集合框架概述   Java集合框架无论是在工作.学习.面试中都会经常涉及到,相信各位也并不陌生,其强大也不用多说,博主最近翻阅java集合框架的源码以 ...

  10. 【EPplus】Column width discrepancy

    description Hi Jan, I have noticed that when I set a column width there is a discrepancy between the ...