http://acm.hdu.edu.cn/showproblem.php?pid=2068
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
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
ll a[26];
void init()
{
a[0]=1;
a[2]=1,a[1]=0;
for(int i=3;i<26;i++) a[i]=(i-1)*( a[i-1]+a[i-2] );
}
ll c(int n,int m)
{
ll a=1;
if(m==0)
return 1;
for(int i=1;i<=m;i++)
{
a=a*(n-i+1);
a=a/i;
}
return a;
}
int main()
{
// freopen("1.txt","r",stdin);
init();
int n;
while(scanf("%d",&n),n)
{
int i;
ll ans=1;
for(i=1;i<=n/2;i++)
{
ans+=a[i]*c(n,i) ;
}
printf("%lld\n",ans);
}
return 0;
}