Statistics

Problem Statement for "SimilarSequencesAnother"

Problem Statement

Two sequences A and B are called similar if they have the same length and have the following property: we can obtain two identical sequences by deleting at most two elements of A and at most two elements of B. (The elements deleted from A don't have to have the same indices as the elements deleted from B. The order of the remaining elements in each sequence has to be preserved.)

You are given ints N and bound. Consider all the sequences with length N such that each element is an integer between 1 and bound, inclusive. Compute the number of ordered pairs of such sequences that are similar. Return this count modulo 1,000,000,009.

Definition

Class:
SimilarSequencesAnother
Method:
getCount
Parameters:
int, int
Returns:
int
Method signature:
int getCount(int N, int bound)
(be sure your method is public)

Constraints

  • N will be between 1 and 100, inclusive.
  • bound will be between 1 and 1,000,000,000, inclusive.

Examples

  1. 2

    10

    Returns: 10000

    Any two 2-element sequences are similar. There are (10^2)^2 = 10,000 pairs of such sequences.

  2. 3

    3

    Returns: 687

    In this case, two sequences are similar if they have at least one element in common. In other words, the two sequences are similar if there is a value that occurs in each of them. Let's count the pairs of sequences that are not similar. There are two possibilities: Each sequence contains the same value three times. For example, one sequence could be {1,1,1} and the other {3,3,3}. There are 6 such pairs. One sequence contains the same value three times, and the other contains the other two values, each of them at least once. For example, one sequence could be {2,3,2} and the other {1,1,1}. There are 2 * 3 * (2^3 - 2) = 36 such pairs. Thus, the total number of pairs of similar sequences is 3^6 - 6 - 36 = 687.

  3. 8

    1

    Returns: 1

  4. 100

    123456789

    Returns: 439681851

  5. 1

    1

    Returns: 1

  6. 1

    2

    Returns: 4

  7. 1

    3

    Returns: 9

  8. 1

    4

    Returns: 16

  9. 2

    1

    Returns: 1

  10. 2

    2

    Returns: 16

  11. 2

    3

    Returns: 81

  12. 2

    4

    Returns: 256

  13. 3

    1

    Returns: 1

  14. 3

    2

    Returns: 62

  15. 3

    3

    Returns: 687

  16. 3

    4

    Returns: 3676

  17. 4

    1

    Returns: 1

  18. 4

    2

    Returns: 234

  19. 4

    3

    Returns: 5343

  20. 4

    4

    Returns: 44524

  21. 100

    1

    Returns: 1

  22. 100

    2

    Returns: 217914523

  23. 100

    3

    Returns: 484211440

  24. 100

    4

    Returns: 679809206

  25. 100

    5

    Returns: 502551462

  26. 100

    818395109

    Returns: 404273259

  27. 99

    756991212

    Returns: 830642202

  28. 98

    689860839

    Returns: 847637721

  29. 97

    943103013

    Returns: 340414540

  30. 96

    828895810

    Returns: 882284188

  31. 95

    691034647

    Returns: 493638054

  32. 94

    755719020

    Returns: 359199298

  33. 93

    483585463

    Returns: 718729268

  34. 1

    342136417

    Returns: 784081955

  35. 2

    122273295

    Returns: 871833043

  36. 3

    584150777

    Returns: 906354115

  37. 4

    850794159

    Returns: 775966753

  38. 5

    425899179

    Returns: 366222125

  39. 6

    179674399

    Returns: 535318194

  40. 7

    708938584

    Returns: 796369975

  41. 8

    252367977

    Returns: 319823228

  42. 100

    14158914

    Returns: 793951634

  43. 100

    365497827

    Returns: 462703330

  44. 100

    626580757

    Returns: 489649654

  45. 100

    907065911

    Returns: 517442713

  46. 100

    871160468

    Returns: 247584739

  47. 10

    226179342

    Returns: 287634341

  48. 30

    213358028

    Returns: 947356867

  49. 50

    23133551

    Returns: 38333137

  50. 70

    831509073

    Returns: 307885020

  51. 90

    21205922

    Returns: 12756903

  52. 100

    1000000000

    Returns: 598436627

  53. 1

    1000000000

    Returns: 81

  54. 99

    1251234

    Returns: 815115868

  55. 100

    555555555

    Returns: 298174317


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: