今年暑假杭电ACM集训队第一次组成女生队,其中有一队叫RPG,但做为集训队成员之一的野骆驼竟然不知道RPG三个人具体是谁谁。RPG给他机会让他猜猜,第一次猜:R是公主,P是草儿,G是月野兔;第二次猜:R是草儿,P是月野兔,G是公主;第三次猜:R是草儿,P是公主,G是月野兔;......可怜的野骆驼第六次终于把RPG分清楚了。由于RPG的带动,做ACM的女生越来越多,我们的野骆驼想都知道她们,可现在有N多人,他要猜的次数可就多了,为了不为难野骆驼,女生们只要求他答对一半或以上就算过关,请问有多少组答案能使他顺利过关。
附上AC代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
const double PI = 3.14159265;
const double E = 2.71828182846;
LL c(int n, int m);
int main()
{
ios::sync_with_stdio(false);
LL d[14] = {1, 0, 1, 2};
for (int i=4; i<14; i++)
d[i] = (i-1)*(d[i-1]+d[i-2]);
int n;
while (cin >> n && n != 0)
{
LL sum = 0;
int flag = n/2;
for (int i=0; i<=flag; i++)
sum += c(n, i)*d[i];
cout << sum << endl;
}
return 0;
}
LL c(int n, int m)
{
LL res = 1, ans = 1;
for (int i=n; i>=n-m+1; i--)
res *= i;
for (int i=1; i<=m; i++)
ans *= i;
return res/ans;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/silenceneo/article/details/47721607