#P3153. [CQOI2009] 跳舞

    ID: 2203 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心2009重庆各省省选网络流最大流

[CQOI2009] 跳舞

Description

There are nn boys and nn girls at a party.

At the start of each song, all boys and girls are paired into exactly nn couples to dance ballroom. No boy ever dances two (or more) songs with the same girl.

Some boy–girl pairs mutually like each other, while others mutually do not; there are no "one-way likes." Each boy is willing to dance with at most kk girls he does not like, and each girl is willing to dance with at most kk boys she does not like.

Given the mutual-like information for every boy–girl pair, what is the maximum number of songs the party can have?

Input Format

The first line contains two integers nn and kk.

Each of the next nn lines contains nn characters, and each character is either Y or N. The jj-th character on line (i+1)(i + 1) is Y if and only if boy ii and girl jj mutually like each other.

Output Format

Output a single integer on one line, representing the maximum number of songs.

3 0
YYY
YYY
YYY
3

Hint

Constraints

  • For 100%100\% of the testdata, it is guaranteed that 1n501 \le n \le 50, 0k300 \le k \le 30.

Translated by ChatGPT 5