fork download
  1. public class DoubleLive {
  2.  
  3. final int MOD = 1000 * 1000 * 1000 + 7;
  4.  
  5. long my_pow(long a, long b) {
  6. long r = 1;
  7. while(b > 0) {
  8. if(b % 2 == 1) r = r * a % MOD;
  9. a = a * a % MOD;
  10. b /= 2;
  11. }
  12. return r;
  13. }
  14. long my_inv(long a) { return my_pow(a, MOD - 2); }
  15.  
  16. public int findEV(int B, int H, int T) {
  17. System.out.println(480 * my_inv(7) % MOD);
  18. long p[][][] = new long[2][B+1][H+B+1];
  19. p[0][B][H] = 1;
  20. long answer = 0;
  21. long memo_inv[] = new long[2*B+H+1];
  22. for(int i = 1; i <= 2 * B + H; ++i)
  23. memo_inv[i] = my_inv(i);
  24. for(int firstBearWounded = 0; firstBearWounded <= 1; ++firstBearWounded)
  25. for(int twos = B; twos >= 0; --twos)
  26. for(int ones = H+B; ones >= 1; --ones) {
  27. long my_p = p[firstBearWounded][twos][ones];
  28. if(my_p == 0) continue;
  29. int alive = twos + ones;
  30. if(2 * B + H - (2 * twos + ones) == T) {
  31. answer = (answer + my_p * alive) % MOD;
  32. continue;
  33. }
  34. my_p = my_p * memo_inv[alive] % MOD;
  35. // a single dies
  36. int a = ones - 1;
  37. if(firstBearWounded == 1) --a;
  38. if(a >= 1) {
  39. p[firstBearWounded][twos][ones-1] += my_p * a;
  40. p[firstBearWounded][twos][ones-1] %= MOD;
  41. }
  42. // a double becomes a single
  43. a = twos;
  44. if(firstBearWounded == 0) --a;
  45. if(a >= 1) {
  46. p[firstBearWounded][twos-1][ones+1] += my_p * a;
  47. p[firstBearWounded][twos-1][ones+1] %= MOD;
  48. }
  49. // the fixed bear gets wounded
  50. if(firstBearWounded == 0) {
  51. p[1][twos-1][ones+1] += my_p;
  52. p[1][twos-1][ones+1] %= MOD;
  53. }
  54. }
  55. answer = answer * B % MOD * H % MOD;
  56. return (int) answer;
  57. }
  58. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class DoubleLive is public, should be declared in a file named DoubleLive.java
public class DoubleLive {
       ^
1 error
stdout
Standard output is empty