codeforces-873C. Strange Game On Matrix[模拟]

本文介绍了一个基于矩阵的游戏,玩家需要通过改变矩阵中的元素来获得最高分数。文章详细解释了游戏规则,并提供了一种求解最优解的方法,包括最大化得分及最小化替换次数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C. Strange Game On Matrix

Ivan is playing a strange game.

He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows:

  1. Initially Ivan's score is 0;
  2. In each column, Ivan will find the topmost 1 (that is, if the current column is j, then he will find minimum i such that ai, j = 1). If there are no 1's in the column, this column is skipped;
  3. Ivan will look at the next min(k, n - i + 1) elements in this column (starting from the element he found) and count the number of 1's among these elements. This number will be added to his score.

Of course, Ivan wants to maximize his score in this strange game. Also he doesn't want to change many elements, so he will replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score he can get and the minimum possible number of replacements required to achieve that score.

Input

The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100).

Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1.

Output

Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score.

Examples

Input

4 3 2
0 1 0
1 0 1
0 1 0
1 1 1

Output

4 1

Input

3 2 1
1 0
0 1
0 0

Output

2 0

Note

In the first example Ivan will replace the element a1, 2.

题意:

给出一个矩阵,可以把矩阵中的1变成0.每次找到每一列的第一个1,计算连续k个有多少1。要求最大的结果。

思路:直接模拟$\sum$(此处检查Latex,请无视)

#include "bits/stdc++.h"
using namespace std;
const int maxn = 100 + 10;
int a[maxn][maxn];
int main(int argc, char const *argv[])
{
    int n,m,k;
    scanf("%d%d%d", &n, &m, &k);
    for(int i = 0; i < n; i++) {
        for(int j = 0;j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    int s1 = 0,s2 = 0;
    for(int j = 0;j < m; j++) {
        int p = 0;
        int maxx = 0;
        int t = 0;
        for(int i = 0;i < n; i++) {
            int cnt = 0;
            for(int l = i;l < n && l-i+1 <= k; l++) {
                if (a[l][j] == 1) cnt++;
            }
            if(maxx < cnt) {maxx = cnt; t = p;}
            p += a[i][j];
        }
        s1 += maxx;
        s2 += t;
    }
    printf("%d %d\n", s1, s2);
    return 0;
}

转载于:https://www.cnblogs.com/cniwoq/p/7682898.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值