C. Strange Game on Matrix time limit/test 1 second memory limit per test 256 megabytes input standard input output STA Ndard output
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 the ones in this matrix with zeroes. After that, he score in the game would be calculated as follows:initially Ivan ' s score is 0; In each column, Ivan'll find the topmost 1 (which is, if the current column are J, then he'll find minimum i such that a I, j = 1). If There are no 1 ' in the column, this column is skipped; Ivan would look at the next min (k, n-i + 1) elements in this column (starting from the element he found) and count the Nu Mber of 1 ' s among these elements. This number is added to his score.
Of course, Ivan wants to maximize he score in this strange game. Also He doesn ' t want to change many elements, so he'll replace the minimum possible number of ones with zeroes. Help him to determine the maximum possible score him can get and the minimum possible # of replacements required to AC Hieve that score. Input
The 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 to get this SCO Re. 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 example Ivan would replace the element A1, 2.
There is a n*m matrix, consisting of 0, 1 .... Operation can be modified to 1 to 0
The scoring method is to count the first 1 (including the first 1) of each column, the array of length k, and the number of 1 .... Sum of results for each column
Ask for the maximum results you can get in the least number of operations.
#include <cstring> #include <queue> #include <cstdio> #include <algorithm> #include <string&
Gt #include <map> #include <set> #include <vector> #include <iostream> #include <cmath> using
namespace Std;
int main () {int n,m,len,in[108][108];
while (~SCANF ("%d%d%d", &n,&m,&len)) {for (int i=0; i<n; i++) for (int j=0; j<m; j + +)
scanf ("%d", &in[i][j]);
int ans1=0,ans2=0;
for (int j=0; j<m; J + +) {int large=0,place;
for (int i=0; i<=n-len; i++) {int sum=0;
for (int k=i; k<i+len; k++) sum+=in[k][j];
if (sum>large) {large=sum;
Place=i;
} if (large) {ans1+=large;
for (int i=0; i<place; i++) ans2+=in[i][j];
} printf ("%d%d\n", ans1,ans2);
return 0;
}