HBC216008圣诞节糖果,二分,分治HarmoniousRectangle题解

坐在坟头思考人生 算法基础篇 29 0
想要成为编程高手?那就来试试全网最全C++题库,让您在练习中快速成长。
A vertex-colored rectangle is a rectangle whose four vertices are all painted with colors. For a vertex-colored rectangle, it's harmonious if and only if we can find two adjacent vertices with the same color, while the other two vertices also have the same color with each other. For example, [1010]begin{bmatrix} 1 & 0\ 1 & 0 end{bmatrix}[1100], [0011]begin{bmatrix} 0 & 0\ 1 & 1 end{bmatrix}[0101] and [1111]begin{bmatrix} 1 & 1\ 1 & 1 end{bmatrix}[1111] are harmonious, while [1001]begin{bmatrix} 1 & 0\ 0 & 1 end{bmatrix}[1001] is not . For each point in {(x,y)∣1≤x≤n,1≤y≤m,x,y∈Z}{(x,y) | 1 le x le n, 1 le y le m, x,y in mathbb{Z}}{(x,y)∣1≤x≤n,1≤y≤m,x,y∈Z}, where Zmathbb{Z}Z is the set of all integers, Kotori wants to paint it into one of the three colors: red, blue, yellow. She wonders the number of different ways to color them so that there exists at least one harmonious rectangle formed by the points, whose edges are all parallel to the xxx- or yyy-axis. That is to say, there exists 1≤x1

A vertex-colored rectangle is a rectangle whose four vertices are all painted with colors. For a vertex-colored rectangle, it's harmonious if and only if we can find two adjacent vertices with the same color, while the other two vertices also have the same color with each other. For example, [1010]begin{bmatrix} 1 & 0\ 1 & 0 end{bmatrix}[11​00​], [0011]begin{bmatrix} 0 & 0\ 1 & 1 end{bmatrix}[01​01​] and [1111]begin{bmatrix} 1 & 1\ 1 & 1 end{bmatrix}[11​11​] are harmonious, while [1001]begin{bmatrix} 1 & 0\ 0 & 1 end{bmatrix}[10​01​] is not (same number for same color, and different numbers for different colors). For each point in {(x,y)∣1≤x≤n,1≤y≤m,x,y∈Z}{(x,y) | 1 le x le n, 1 le y le m, x,y in mathbb{Z}}{(x,y)∣1≤x≤n,1≤y≤m,x,y∈Z}, where Zmathbb{Z}Z is the set of all integers, Kotori wants to paint it into one of the three colors: red, blue, yellow. She wonders the number of different ways to color them so that there exists at least one harmonious rectangle formed by the points, whose edges are all parallel to the xxx- or yyy-axis. That is to say, there exists 1≤x1

HBC216008圣诞节糖果,二分,分治HarmoniousRectangle题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
成为编程大师,不再是梦想!全网最全C++题库,助您开启编程新篇章。

标签: HBC216008圣诞节糖果 二分 分治HarmoniousRectangle题解