RPG的错排

Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 55   Accepted Submission(s) : 32

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

今年暑假杭电ACM集训队第一次组成女生队,其中有一队叫RPG,但做为集训队成员之一的野骆驼竟然不知道RPG三个人具体是谁谁。RPG给他机会让他猜猜,第一次猜:R是公主,P是草儿,G是月野兔;第二次猜:R是草儿,P是月野兔,G是公主;第三次猜:R是草儿,P是公主,G是月野兔;......可怜的野骆驼第六次终于把RPG分清楚了。由于RPG的带动,做ACM的女生越来越多,我们的野骆驼想都知道她们,可现在有N多人,他要猜的次数可就多了,为了不为难野骆驼,女生们只要求他答对一半或以上就算过关,请问有多少组答案能使他顺利过关。

Input

输入的数据里有多个case,每个case包括一个n,代表有几个女生,(n<=25), n = 0输入结束。

Sample Input

1
2
0

Sample Output

1
1

Author

Rabbit

Source

RPG专场练习赛

——————————————————————————————
思路:对的要达到一半或以上,只要选一半或以下的数进行错排即可

错排公式 a[1]=0,a[2]=1,a[i]=(i-1)*(a[i-1]+a[i-2]);


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath> using namespace std; #define LL long long
const int inf=0x7fffffff;
LL a[30];
LL C(int x,int n)
{
LL ans=1;
for(int i=1;i<=x;i++)
{
ans*=(n-i+1);
ans/=i;
}
return ans;
} int main()
{
int n;
a[0]=1;
a[1]=0;
a[2]=1;
for(int i=3;i<=12;i++)
{
a[i]=(i-1)*(a[i-1]+a[i-2]);
//printf("%d\n",a[i]);
}
while(~scanf("%d",&n)&&n)
{
LL ans=0;
for(int i=0;i<=n/2;i++)
{
ans+=C(i,n)*a[i];
}
printf("%lld\n",ans);
}
return 0;
}

最新文章

  1. MAC OS PHP
  2. thinkphp端口配置
  3. Android之下拉刷新,上啦加载的实现(一)
  4. 第六章 prototype和constructor
  5. sudo: unable to resolve host ubuntu提示的解决
  6. C#三大支柱之继承
  7. Swift学习笔记五
  8. CF Drazil and Date (奇偶剪枝)
  9. WPF中Expander控件样式,ListBox的样式(带checkbox)恢复
  10. 执行一条cmd命令的window.bat 批处理代码:
  11. UITableView滑动按钮的操作
  12. 解决getElementsByClassName兼容问题
  13. 在 redhat 6.4上安装Python 2.7.5
  14. LeetCode 11. Container With Most Water (装最多水的容器)
  15. ASP.NET Boilerplate-AbpSession
  16. P4822 [BJWC2012]冻结
  17. UI复习练习_优酷布局
  18. 转载-LVS的三种工作模式
  19. ISE14.7生成.bit文件和mcs文件
  20. mycat 管理MySQL5.7主从搭建

热门文章

  1. Maven 系列 二 :Maven 常用命令,手动创建第一个 Maven 项目
  2. 758B Blown Garland
  3. 比较两个List列表,取得List中不同项返回
  4. python基础之Day5
  5. 部署描述符(web.xml)和标注(annotation)
  6. linux系统,在centos7环境下安装jdk步骤
  7. 【Linux】Jenkins+Git源码管理(三)
  8. svn log — 显示提交日志信息
  9. Java第15章笔记
  10. sql心跳