This page is still under construction.

Parts of this page are still being built. What you see may change.

Jan's coloring book

Time limit1sMemory limit64 MB

Summary
Count proper colorings of one of eight fixed maps using at most three of K colors with adjacent areas different.
Level

Medium7 of 10

Topics
Graph, Combinatorics, Dynamic programming
Solved
No attempts yet

Problem

Jan liked coloring as a child. He is now a student of electrical engineering, and he bought a coloring book and KK distinct colors so he can color again.

Jan does not like busy pictures, so he colors each picture with at most three different colors. He never gives the same color to two adjacent areas. If two areas share a line, he says there is no point in drawing that line and then painting both sides the same.

Two areas are adjacent when their boundaries share at least one point. In picture 3 below, areas 44 and 33 are adjacent, and areas 11 and 22 are not.

Before he starts, Jan wants the number of valid ways to color the chosen picture. Two colorings differ when at least one area has a different color.

The eight pictures are the maps below. Each vertex is an area that must be colored. Each edge joins two areas that share a boundary point. Eyes, antennae, and gray fill are not areas and are not colored.

Input

The first and only line contains two integers NN and KK (1≤N≤81 \leq N \leq 8, 1≤K≤10001 \leq K \leq 1000): the index of the picture in the book and the number of colors Jan may use.

Output

Print one integer: the number of ways Jan can color picture NN using the KK colors, with at most three colors appearing on the picture and with adjacent areas colored differently.

Pictures

Picture 1. Caterpillar. The body is a path of 2020 disks. Only consecutive disks are adjacent. The eyes and the antennae are not areas.

Picture 2. A sea cottage. The dual graph has 88 vertices: 00 is the wall, 11 is the door, 22 and 33 are the two panes of the left window, 44 and 55 are the two panes of the right window, 66 is the roof, and 77 is the attic window. The edges are 0−10{-}1, 0−20{-}2, 0−30{-}3, 0−40{-}4, 0−50{-}5, 0−60{-}6, 2−32{-}3, 4−54{-}5, 6−76{-}7.

Picture 3. A well known logo. Inner disk 11 and inner oval 22 do not touch each other. Both sit in white interior 33. Outer frame 44 touches only the white interior. The edges are 1−31{-}3, 2−32{-}3, 3−43{-}4.

Picture 4. Frosty the Snowman. The dual graph is a tree on 1414 vertices. The spine is 0−1−2−5−90{-}1{-}2{-}5{-}9. Vertex 22 is also adjacent to 33 and 44, vertex 55 is also adjacent to 66, 77, and 88, and vertex 99 is also adjacent to 1010, 1111, 1212, and 1313.

Picture 5. An abstract ball. Concentric rings, with a horizontal cut through the inner disk and the outer ring but not through the middle ring. Vertices: inner top 00, inner bottom 11, middle ring 22, outer top 33, outer bottom 44. Edges: 0−10{-}1, 0−20{-}2, 1−21{-}2, 2−32{-}3, 2−42{-}4, 3−43{-}4.

Picture 6. Pyramid. There are 1010 rows of bricks. Row rr has rr bricks (1≤r≤101 \leq r \leq 10). Consecutive bricks in a row are adjacent. The jj-th brick in row rr (from the left) rests on bricks jj and j+1j{+}1 of row r+1r{+}1, and is adjacent to both.

Picture 7. Daisy. The dual graph is the same as picture 2.

Picture 8. Trampoline. The gray disk is not an area. The white rim is a 3030-cycle: 3030 sectors around the disk, with only consecutive sectors adjacent.

Examples5

  1. Example 1

    Input
    2 2
    
    Expected output
    0
    
  2. Example 2

    Input
    5 3
    
    Expected output
    12
    
  3. Example 3

    Input
    7 3
    
    Expected output
    96
    
  4. Example 4

    Input
    3 2
    
    Expected output
    2
    
  5. Example 5

    Input
    6 3
    
    Expected output
    6