fork download
  1.  
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. public class DrBTreeII {
  6.  
  7. static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
  8. static StringTokenizer st = new StringTokenizer("");
  9.  
  10. public static String next() {
  11. try {
  12. while (!st.hasMoreTokens()) {
  13. String s = br.readLine();
  14. if (s == null)
  15. return null;
  16. st = new StringTokenizer(s);
  17. }
  18. return st.nextToken();
  19. } catch(Exception e) {
  20. return null;
  21. }
  22. }
  23. public static void main(String[] asda) throws Exception {
  24. mem = new int [1005][1005];
  25. for (int [] v : mem) Arrays.fill(v, -1);
  26.  
  27. int CASES = Integer.parseInt( next() );
  28. while (CASES-- > 0) {
  29. int L = Integer.parseInt( next() );
  30. int K = Integer.parseInt( next() );
  31.  
  32. int ans = solve(L, K);
  33. out.println( ans );
  34. }
  35. //
  36. out.flush();
  37. System.exit(0);
  38. }
  39.  
  40. static final long MOD = 1000000000 + 7, CHARS = 10;
  41. static int [][] mem;
  42. static int solve(int len, int mirrors) {
  43. if (len == 0 && mirrors == 0) {
  44. return 1;
  45. }
  46. if (len < 0 || mirrors < 0) {
  47. return 0;
  48. }
  49.  
  50. if (mem[len][mirrors] != -1) {
  51. return mem[len][mirrors];
  52. }
  53.  
  54. long ans = 0;
  55. if (len % 2 == 1) {
  56. // place middle
  57. ans = CHARS * solve(len - 1, mirrors - 1);
  58. ans %= MOD;
  59. } else {
  60. // place not mirror
  61. ans = CHARS * (CHARS - 1) * solve(len - 2, mirrors);
  62. ans %= MOD;
  63.  
  64. ans += CHARS * solve(len - 2, mirrors - 1);
  65. ans %= MOD;
  66. }
  67. // out.printf("solve(%d, %d) = %d\n", len, mirrors, ans);
  68. return mem[len][mirrors] = (int)ans;
  69. }
  70.  
  71. }
  72.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class DrBTreeII is public, should be declared in a file named DrBTreeII.java
public class DrBTreeII {
       ^
1 error
stdout
Standard output is empty