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 <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <vector> #include <cmath> #include <queue> #include <deque> #include <cmath> #include <map> using namespace std; typedef long long ll; #define INF 0x7fffffff const double inf=1e20; const int maxn=1e6+10; const int mod=1e9+7; ll ans[20]; int n; ll getC(ll n,ll x) { ll ans=1; for(int i=0;i<x;i++){ ans=ans*(n-i)/(i+1); } return ans; } int main() { ans[1] = 0; ans[2] = 1; for(int i=3;i<=25;i++) { ans[i]=(ans[i-1]+ans[i-2])*(i-1); } while(scanf("%d",&n)!=EOF){ if(n==0)break; ll num=1; int m=(n)/2; for(int i=1;i<=m;i++) { num+=ans[i]*getC(n,i); } printf("%lld\n",num); } return 0; }