Statistics

Problem Statement for "CharmingTicketsEasy"

Problem Statement

A ticket number that contains exactly 2*K digits is called charming if and only if at least one of the following conditions is satisfied:

  • The sum of the first K digits is equal to the sum of the last K digits.
  • The sum of all the digits at positions with odd indices is equal to the sum of all the digits at positions with even indices.

Also, you think that some digits are better than others, so a charming number must contain only digits that you consider to be good. These digits are given in the String good. Determine the number of different charming numbers containing exactly 2*K digits. Return this number modulo 999983. Remember that ticket numbers may contain leading zeroes.

Definition

Class:
CharmingTicketsEasy
Method:
count
Parameters:
int, String
Returns:
int
Method signature:
int count(int K, String good)
(be sure your method is public)

Constraints

  • K will be between 1 and 50, inclusive.
  • good will contain between 1 and 10 characters, inclusive.
  • good will contain only digits ('0' - '9').
  • All characters in good will be distinct.

Examples

  1. 1

    "0123456789"

    Returns: 10

    Only "XX" numbers are charming.

  2. 2

    "21"

    Returns: 8

    Only 1111, 1122, 1212, 1221, 2112, 2121, 2211, 2222 are charming numbers.

  3. 2

    "0123456789"

    Returns: 1240

  4. 10

    "731"

    Returns: 207444

  5. 50

    "0123456789"

    Returns: 367584

  6. 46

    "28759604"

    Returns: 537052

  7. 42

    "54"

    Returns: 116022

  8. 46

    "274638"

    Returns: 29046

  9. 32

    "34297"

    Returns: 486282

  10. 6

    "439875"

    Returns: 580456

  11. 4

    "028"

    Returns: 1069

  12. 32

    "861207"

    Returns: 227373

  13. 39

    "285"

    Returns: 710103

  14. 42

    "176"

    Returns: 899874

  15. 49

    "8726531049"

    Returns: 876299

  16. 47

    "402593"

    Returns: 234511

  17. 4

    "6028"

    Returns: 10296

  18. 48

    "1"

    Returns: 1

  19. 35

    "73125869"

    Returns: 977384

  20. 31

    "23810654"

    Returns: 986367

  21. 6

    "4831"

    Returns: 422969

  22. 20

    "384167"

    Returns: 914891

  23. 42

    "2148397"

    Returns: 544617

  24. 6

    "60712"

    Returns: 337996

  25. 23

    "50762"

    Returns: 19513

  26. 8

    "49321"

    Returns: 389517

  27. 11

    "371"

    Returns: 493152

  28. 40

    "125836"

    Returns: 805706

  29. 28

    "3904716"

    Returns: 182674

  30. 7

    "4670592"

    Returns: 578619

  31. 4

    "32658"

    Returns: 46977

  32. 34

    "7"

    Returns: 1

  33. 11

    "743861"

    Returns: 299634

  34. 22

    "0718239"

    Returns: 34748

  35. 49

    "89315"

    Returns: 193554

  36. 25

    "592041"

    Returns: 894605

  37. 34

    "6702"

    Returns: 456512

  38. 14

    "3692"

    Returns: 676028

  39. 31

    "375"

    Returns: 61430

  40. 4

    "0952"

    Returns: 5720

  41. 12

    "2"

    Returns: 1

  42. 9

    "6314087"

    Returns: 472064

  43. 27

    "3104972"

    Returns: 753243

  44. 25

    "789465"

    Returns: 237740

  45. 46

    "936042"

    Returns: 458106

  46. 50

    "0836"

    Returns: 214321

  47. 38

    "30"

    Returns: 470649

  48. 9

    "6784"

    Returns: 38341

  49. 49

    "806741"

    Returns: 512499

  50. 24

    "0"

    Returns: 1

  51. 38

    "23109"

    Returns: 837253

  52. 42

    "289"

    Returns: 125260

  53. 31

    "90671238"

    Returns: 861199

  54. 19

    "06783519"

    Returns: 607781

  55. 29

    "01694"

    Returns: 664591

  56. 42

    "53689012"

    Returns: 986309

  57. 12

    "9876543120"

    Returns: 831746

  58. 50

    "0145678932"

    Returns: 367584

  59. 47

    "125893"

    Returns: 473425


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: