I caculated it directly and my program got ACed in 1.9x(sec).

But many people's programs used much less time. I wonder how they made it.
Moderator: Board moderators
Code: Select all
C(n,k) = C(n-1,k) * n / (n-k)
Code: Select all
c(n, k) = c(n, k-1) * (n-k+1) / k
Hello, PerPer wrote:There will be overflow if you just use the formula i wrote as well, you just have to be careful enough to avoid it.
Code: Select all
44 26
11 33
35 34
300 143
1 1
0 1
Code: Select all
6852201722390613528
6118171326
<illegal test case>
<illegal test case>
1
1
Code: Select all
15 111
958 8
Code: Select all
9188907830737093233
9171632935212769528
Code: Select all
#include <stdio.h>
#define MAXN 1000
int main()
{
unsigned long f[MAXN + 1]; /* f[n] = f(n, v) */
int n, v;
int i, start;
while (1) {
scanf("%d %d", &n, &v);
if ((n == 0) && (v == 0))
break;
f[0] = 1;
f[1] = (unsigned long)v;
start = (n % 2 == 0 ? 0 : 1);
for(i = start; i <= n - 2; i+=2)
f[i + 2] = f[i] * ((i + v)*(i + v + 1)) / ((i + 1)*(i + 2));
for(i = start; i < n; i+=2)
f[n] += f[i];
printf("%ld\n", f[n]);
}
return 0;
}
Code: Select all
Removied after AC
Your solution gets Segmentation fault on:Khaled_912 wrote:I'm keeping to get WA on this problem, although I've tried all of the test cases in the other posts.
If anybody can tell me where's the mistake or post some extra i/o I'll be thankful.
Code: Select all
6 1000
0 0
Code: Select all
1409882508284251