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
C(n,k) = C(n-1,k) * n / (n-k)c(n, k) = c(n, k-1) * (n-k+1) / kPer 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.
44 26
11 33
35 34
300 143
1 1
0 1

6852201722390613528
6118171326
<illegal test case>
<illegal test case>
1
115 111
958 89188907830737093233
9171632935212769528
#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;
}
Yaron Wittenstein wrote:What's worng? i have no idea, maybe it has something to do with the fact that the answer will fit a 64-bit signed integer?

Removied after AC
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.
6 1000
0 01409882508284251
Users browsing this forum: No registered users and 1 guest