Lazy girl
Time Limit : 1 seconds Memory Limit : 10MB
Tracy and her classmates are learning combinatory. Today’s homework is to calculate some equation like. Tracy is a lazy girl, so she decides to calculate them with computer. Suppose you are the computer, then what’s the answer?
Input:
The input file contains several test cases. For each test case:
There’s only one line containing two integers n (n>=1) and k (0<=k<=n). Input is terminated by two zeroes for n and k.
Output:
For each test case, print one line containing the required number. This number will always fit into an 64-bit integer, i.e. it will be less than 263.
Sample Input:
4 2
10 5
49 6
0 0
Sample Output:
6
252
13983816
----------------解决方案--------------------------------------------------------
弄成汉语行不?
----------------解决方案--------------------------------------------------------
# include<stdio.h>
long int f(int n,int r)
{
if (r==0||r==n)
return 0;
else
return f(n-1,r-1)+f(n-1,r-1);
}
int main()
{
int n,r;
long int t;
scanf("%d %d",&n,&r);
while(n!=0&&r!=0)
{
t=f(n,r);
printf("%ld\n",t);
scanf("%d %d",&n,&r);
}
return 0;
}
----------------解决方案--------------------------------------------------------
呵呵!
这个肯定会超时的!!
----------------解决方案--------------------------------------------------------
这个是昨天的ACM竞赛题目.
翻译一下:
懒惰的女孩
时间限制:1S 内存限制:10M
特蕾西和她的同学正在学习组合数,今天她们的作业句是计算如下的等式.特蕾西是一个非常懒惰的女孩,于是她决定运用计算机帮它解决,假设,你就是计算机,问这些答案是什么?
输入:
输入文件要包含多组测试数据,对于每组测试数据:
每行包括两个整数n (n>=1) and k (0<=k<=n).以给n,k输入0结束测试.
输出:
对每组测试数据,每行显示一个要求的数,这个数适用于64位整型.也就是小于263.
/*也不知道这样翻可以不,反正知道意思就可以了.*/
----------------解决方案--------------------------------------------------------