Karte

시간 제한1초메모리 제한2048 MB

요약
N×M 0/1 행렬과 비용 X, Y가 주어질 때, 빨간 카드와 파란 카드의 부분집합을 골라 (콤보 쌍 수) - X·(빨간 카드 수) - Y·(파란 카드 수)를 최대로 만드는 값을 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 비트 연산, 완전 탐색
정답자
아직 제출이 없습니다

문제

On Vito’s table, there are NN red cards labeled with numbers from 11 to NN and MM blue cards labeled with numbers from 11 to MM. Each pair of red and blue cards (c,p)(c, p) (where cc represents a red card and pp a blue card) can create a COMBO move.

The strength of a deck of cards is defined as:

strength = (number of COMBO moves) - XX · (number of red cards) − YY · (number of blue cards)

where the number of COMBO moves is the number of pairs (c,p)(c, p) such that the red card cc and the blue card pp are in the chosen deck. Vito can include any card from the table in his deck. Help Vito find the value of the strongest deck he can build. Vito can also choose an empty deck of cards.

입력

The first line contains 44 natural numbers NN, MM, XX, YY (1≤N,M≤211 ≤ N, M ≤ 21, 0≤X,Y≤300 ≤ X, Y ≤ 30).

In the next NN lines, there is a sequence of $$M characters (00 or 11), where the jj-th character indicates whether the ii-th red card and the jj-th blue card create a COMBO move.

출력

In the first and only line, output the value of the strongest deck of cards that Vito can build.

힌트

Explanation of the first sample case: Vito will choose all the cards from the table, creating 33 COMBO moves.

Explanation of the second sample case: Vito will select the first 22 red cards and all 33 blue cards, creating 66 COMBO moves. The deck strength is 44 because Vito selected $$2 red cards, so the number of COMBO moves, i.e., 66, is reduced by 22.

예제3

  1. 예제 1

    입력
    2 2 0 0
    11
    10
    
    예상 출력
    3
    
  2. 예제 2

    입력
    3 3 1 0
    111
    111
    000
    
    예상 출력
    4
    
  3. 예제 3

    입력
    3 3 1 1
    111
    101
    011
    
    예상 출력
    1