UVALive 4123 Glenbow Museum (组合数学)
转载请注明出处: 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 (组合数学)的更多相关文章
- LA 4123 - Glenbow Museum
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- LA 4123 (计数 递推) Glenbow Museum
题意: 这种所有边都是垂直或水平的多边形,可以用一个字符串来表示,一个270°的内角记作O,一个90°的内角记作R. 如果多边形内存在一个点,能看到该多边形所有的点,则这个多边形对应的序列是合法的.这 ...
- 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是奇数时无解. ...
- 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 ...
- UVALive 7143 Room Assignment(组合数学+DP)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- UVaLive 7267 Mysterious Antiques in Sackler Museum (if-else,枚举)
题意:给定四个矩形,要求从中选出三个,能不能拼成一个矩形. 析:说到这个题,我还坑了队友一次,读题读错了,我直接看的样例,以为是四个能不能组成,然后我们三个就拼命想有什么简便方法,后来没办法了,直接暴 ...
- UVALive 7143 Room Assignment(组合数学+DP)
题目链接 参考自:http://www.cnblogs.com/oyking/p/4508260.html 题意 n个人,其中有k对双胞胎.现有m间房间,每间房间有容量ci问分配房间的方案数. 分析 ...
- UVALive 5099
B - Nubulsa Expo Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- UVALive 5099 Nubulsa Expo 全局最小割问题
B - Nubulsa Expo Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
随机推荐
- BestCoder Round #81 (div.2)1001
Machine Accepts: 580 Submissions: 1890 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65 ...
- C语言中的静态局部变量
代码: 0x601070 0x7ffcf44243fc 0x60106c 0x60106c 0x60106c [hu@localhost test]$ cat test.cpp #include &l ...
- angularjs如何在ng-repeat过程中控制字符串长度超过指定长度后面内容以省略号显示
angular.module('ng').filter('cut', function () { return function (value, wordwise, max, tail) { if ( ...
- (原)ubuntu16重装显卡驱动后,torch中的问题
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6030232.html 参考网址: https://github.com/torch/cutorch/i ...
- 搭建hbase-0.94.26集群环境
先安装hadoop1.2.1,见http://blog.csdn.net/jediael_lu/article/details/38926477 1.配置hbase-site.xml <prop ...
- jQuery输入框提示自动完成插件 autocomplete
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- JavaScript 作用域和闭包
作用域的嵌套将形成作用域链,函数的嵌套将形成闭包.闭包与作用域链是 JavaScript 区别于其它语言的重要特性之一. 作用域 JavaScript 中有两种作用域:函数作用域和全局作用域. 在一个 ...
- ubuntu 执行apt-get update 提示无法获得锁
问题如下: y@y:~$ sudo apt-get updateE: 无法获得锁 /var/lib/apt/lists/lock - open (11: 资源暂时不可用)E: 无法对目录 /var/l ...
- openwrt下和云端通讯的例程,
openwrt下和云端通讯的例程 ibcurl 官方文档请参考这里 http://curl.haxx.se/libcurl/c/curl_easy_setopt.html 刚接触 libcurl的时候 ...
- c# 编程添加控件
Button b = new Button();//创建一个新的按钮 b.Text = "test"; //添加到panel1中 panel1.Controls.Add(b);