RPG的错排

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13155    Accepted Submission(s): 5378

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的错排
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2068
题意:有N多人,他要猜的次数可就多了,为了不为难野骆驼,女生们只要求他答对一半或以上就算过关,请问有多少组答案能使他顺利过关。
思路:枚举答错的名字数。注意答错名字数0,和答错名字数1都是表示答对所有的这一种情况。 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int mod=1e9+;
const int maxn=1e6+;
int T, n;
LL M[];
void init()
{
M[] = ;
M[] = ;
for(int i = ; i <= ; i++){
M[i] = (i-)*(M[i-]+M[i-]);
}
}
LL C(LL n,LL m)
{
LL p = ;
for(int i = n-m+; i<=n; i++) p = p*i;
for(int i = ; i <= m; i++) p = p/i;
return p;
}
int main()
{
init();
while(scanf("%d",&n)!=EOF)
{
if(n==) break;
LL ans = ;
int x = n/;
while(x>){
ans += C(n,x)*M[x];
x--;
}
///x=0与x=1都是代表全部答对这一种情况;
ans ++;
printf("%lld\n",ans);
}
return ;
}
05-08 14:57