今年暑假杭电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输入结束。Output
1
1
Sample Input
1
2
0
Sample Output
1
1
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
LL ans[20];
int n;
LL getsd(LL n,LL x) {
LL ret = 1;
for(int i = 0; i < x; i ++) {
ret = ret * (n - i) /(i + 1);
}
return ret;
}
int main() {
ans[0] = 1;
ans[1] = 0;
ans[2] = 1;
for(int i = 3; i <= 15 ; i ++) {
ans[i] = (ans[i - 1] + ans[i - 2]) * (i - 1);
}
while(~ scanf("%d", &n), n) {
LL ret = ans[0];
int m = n >> 1;
for(int i = 1; i <= m; i ++) {
ret += ans[i] * getsd(n,i);
}
printf("%I64d\n",ret);
}
return 0;
}
nclude <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
LL ans[20];
int n;
LL getsd(LL n,LL x) {
LL ret = 1;
for(int i = 0; i < x; i ++) {
ret = ret * (n - i) /(i + 1);
}
return ret;
}
int main() {
ans[0] = 1;
ans[1] = 0;
ans[2] = 1;
for(int i = 3; i <= 15 ; i ++) {
ans[i] = (ans[i - 1] + ans[i - 2]) * (i - 1);
}
while(~ scanf("%d", &n), n) {
LL ret = ans[0];
int m = n >> 1;
for(int i = 1; i <= m; i ++) {
ret += ans[i] * getsd(n,i);
}
printf("%I64d\n",ret);
}
return 0;
}
题解:题很简单,就是一直WA