转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

易得,当n为奇数或者n<3时,答案为0,否则该序列中必定有(n+4)/2个R,(n-4)/2个O;

要使该序列的排列能成立,则只需要保证(在首尾相连之后)该序列中依旧不存在相连的两个O即可;

从而可以得出当n为大于等于4的偶数时,答案等于C(n/2+1,3)+2*C(n/2+1,4);

当然,大白书还有介绍dp的方法。

 #include <iostream>
using namespace std;
typedef long long ll;
ll C[][];
ll ans[];
int main()
{
ios::sync_with_stdio(false);
C[][]=;
for(int i=;i<;i++)
{
C[i][]=;
for(int j=;j<;j++)
{
C[i][j]=C[i-][j-]+C[i-][j];
}
}
for(int i=;i<;i++)
{
if(i&)continue;
else ans[i]=*C[i/+][]+C[i/+][];
}
int n,cas=;
while(cin>>n&&n)
{
cout<<"Case "<<cas++<<": "<<ans[n]<<endl;
}
return ;
}

UVALive 4123 Glenbow Museum (组合数学)的更多相关文章

  1. LA 4123 - Glenbow Museum

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

  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. UVALive 7267 Mysterious Antiques in Sackler Museum (判断长方形)

    Sackler Museum of Art and Archaeology at Peking University is located on a beautiful site near the W ...

  5. UVALive 7143 Room Assignment(组合数学+DP)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  6. UVaLive 7267 Mysterious Antiques in Sackler Museum (if-else,枚举)

    题意:给定四个矩形,要求从中选出三个,能不能拼成一个矩形. 析:说到这个题,我还坑了队友一次,读题读错了,我直接看的样例,以为是四个能不能组成,然后我们三个就拼命想有什么简便方法,后来没办法了,直接暴 ...

  7. UVALive 7143 Room Assignment(组合数学+DP)

    题目链接 参考自:http://www.cnblogs.com/oyking/p/4508260.html 题意 n个人,其中有k对双胞胎.现有m间房间,每间房间有容量ci问分配房间的方案数. 分析 ...

  8. UVALive 5099

    B - Nubulsa Expo Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  9. UVALive 5099 Nubulsa Expo 全局最小割问题

    B - Nubulsa Expo Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

随机推荐

  1. mysql 8小时空闲后连接失效的解决

    查了一下发现应用程序和mysql数据库建立连接,如果超过8小时应用程序不去访问数据库,数据库就断掉连接 .这时再次访问就会抛出异常. 关于mysql自动断开的问题研究结果如下, 1.c3p0.Hika ...

  2. js prototype之诡异

    想必经常写js的人必然会经常性的用到prototype这个属性,我写这篇文章倒不是自己对prototype这个属性理解有多深刻,相反是因为自己理解肤浅,想通过写文章来加深理解.废话不多说.下面总结一下 ...

  3. PHP & JAVA 实现 PBKDF2 加密算法

    PHP代码: /** * PBKDF2 加密函数 * 参考标准 * @link https://www.ietf.org/rfc/rfc2898.txt * * php官方函数将在php5.5发布 * ...

  4. Python基础第四天

    必须掌握的内置函数 bytes() divmod() eval() exec() isinstance() range() 常用函数 1.数学相关 abs(x) abs()返回一个数字的绝对值.如果给 ...

  5. 百度地图api实例

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm11.aspx ...

  6. [TYVJ] P1023 奶牛的锻炼

    奶牛的锻炼 背景 Background USACO   描述 Description 奶牛Bessie有N分钟时间跑步,每分钟她可以跑步或者休息.若她在第i分钟跑步,可以跑出D_i米,同时疲倦程度增加 ...

  7. Android SDCard和内部存储中gcc编译后的可执行文件无法运行提示 cannot execute - Permission denied

    原因是mount的方式问题,root后运行 su mount -o rw,remount /mnt/sdcard   //SDCard mount -o rw,remount /mnt/interna ...

  8. Oracle case用法

    1:update 时做检查使用update mw_contract set payTimes=( case else payTimes end )'; 2:select时使用 select case ...

  9. cf C. Tourist Problem

    http://codeforces.com/contest/340/problem/C #include <cstdio> #include <cstring> #includ ...

  10. LeetCode_Recover Binary Search Tree

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...