Hdu2068 RPG的错排 2017-06-27 15:27 30人阅读 评论(0) 收藏
2024-10-19 01:24:45
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;
}
最新文章
- MAC OS PHP
- thinkphp端口配置
- Android之下拉刷新,上啦加载的实现(一)
- 第六章 prototype和constructor
- sudo: unable to resolve host ubuntu提示的解决
- C#三大支柱之继承
- Swift学习笔记五
- CF Drazil and Date (奇偶剪枝)
- WPF中Expander控件样式,ListBox的样式(带checkbox)恢复
- 执行一条cmd命令的window.bat 批处理代码:
- UITableView滑动按钮的操作
- 解决getElementsByClassName兼容问题
- 在 redhat 6.4上安装Python 2.7.5
- LeetCode 11. Container With Most Water (装最多水的容器)
- ASP.NET Boilerplate-AbpSession
- P4822 [BJWC2012]冻结
- UI复习练习_优酷布局
- 转载-LVS的三种工作模式
- ISE14.7生成.bit文件和mcs文件
- mycat 管理MySQL5.7主从搭建