Moderator: Board moderators

Abednego wrote:To Krzyszof: really!? That's not good. I'll look into it.

Diego Caminha wrote:Can anyone help me? I know the problem is solved with DP but my probability skills are limited and I can't think a way of solving it properly! The only way I found that solves the problem is (or something very similar, i didn't coded it, just solved the sample input):
P(k, m) = p0^k + W(k,1)*P(1, m-1) + W(k,2)*P(2,m-1) + ... + W(k, k*(n-1))*P(k*(n-1), m-1);
Where:
- k, m, n, p are the same as in text
- P(k, m) is the probability of k Tribbles will be dead after m generations
- W(k, x) is the number of ways k Trilbbles can give birth to x Tribbles
For instance:
when n = 3, k = 2, m = 3;
P(2,3) = P(0, 2) + 2*P(1, 2) + 3*P(2, 2) + 2*P(3,2) + 1*P(4,2);
and:
P(4,2) = P(0,1) + 4*P(1,1) + 10*P(2,1) + ... + ?*P(8,1);
As you can see, the number of Tribbles and the combinations (W) grow a lot.
Is there a way where the problem is solved having to worry with fewer things? Please, any hint would be welcome.

#include<stdio.h>
#include<math.h>
int main() {
int t, i;
for( scanf("%d", &t); t--; ) {
scanf("%d %d %d", &n, &K, &M);
for(i=0;i<n;i++) scanf("%lf", &pro[i]);
for(i=1;i<=M;i++) dp[i] = -1;
printf("%.7lf\n", memo(M, K) );
}
return 0;
}
#include<stdio.h>
#include<math.h>
int main() {
int t, i, cases = 1;
for( scanf("%d", &t); t--; ) {
scanf("%d %d %d", &n, &K, &M);
for(i=0;i<n;i++) scanf("%lf", &pro[i]);
for(i=1;i<=M;i++) dp[i] = -1;
printf("Case #%d: %.7lf\n",cases++, memo(M, K) );
}
return 0;
}

Users browsing this forum: No registered users and 0 guests