hdu 2068 RPG的錯排

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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章