Bzoj 2241: [SDOI2011] hit the ground rat violence

Source: Internet
Author: User
Tags gopher

2241: [SDOI2011] hit the ground rat

Time Limit:1 Sec

Memory limit:256 MB

Topic Connection http://www.lydsy.com/JudgeOnline/problem.php?id=2241
Description

The hamster is a game in which there are some hamster holes on the ground, and the hamsters will come out of the hole from time to time and then retract into the hole. The goal of the player is to hit the head with a hammer when the ground mouse reaches out, and the more points it gets, the higher the score.

The hammer in the game can only hit one gopher at a time, and if multiple hamsters are at the same time, the player can only knock out all the hamsters by swinging the hammer multiple times. You think the hammer is too useless, so you modified the hammer to increase the contact area between the hammer and the ground, so that it can hit an area at a time. If we think of the ground as a m*n square, each element represents a gopher hole, then the hammer can cover all the hamster holes in the r*c area. But the modified Hammer has one drawback: every time a hammer is waved, the hammer will knock out exactly one gopher for all the holes in the R*c area. That is to say, in the area where the hammer is covered, there must be at least 1 hamsters in each burrow, and if the number of hamsters in a burrow is greater than 1, then only 1 hamsters will be knocked out of the burrow, so every time a hammer is waved, just R*c is knocked out. Because the internal structure of the hammer is too sophisticated, you cannot rotate the hammer during the game (that is, you cannot swap R and C).

You can arbitrarily change the size of the hammer (that is, you can arbitrarily specify R and c sizes), but the work of a modified hammer can only be done in front of the hamster (i.e. you cannot knock off a part of the hamster and then change the hammer's specifications). Your task is to find out if you want to destroy all the hamsters, at least the number of times you need to wield a hammer.

Hint: Since you can set the size of the hammer to 1*1, there is always a solution to the subject.

Input

The first line consists of two positive integers m and N;

The following m lines describe the map in rows of n positive integers, each representing the number of hamsters in the burrow at the corresponding location.

Output

Outputs an integer that represents the minimum number of flapping times.

Sample INPUT3 3

1 2 1

2 4 2

1 2 1

Sample Output

4HINT

Test instructions

Exercises

is not satisfied with the dichotomy of nature, direct violence is good

N^4 the complexity of the party, just run naked.

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<bitset>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 200500#defineMoD 1001#defineEPS 1e-9#definePi 3.1415926intNum;//const int INF=0X7FFFFFFF;Constll inf=999999999; inline ll read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//*************************************************************************************intm[ the][ the];intsum =0;intAns =inf;intt[ the][ the];intn,m;voidWorkintXinty) {     for(intI=1; i<=n;i++)         for(intj=1; j<=m;j++) T[i][j]=M[i][j];  for(intI=1; i<=n;i++)    {         for(intj=1; j<=m;j++)        {            if(T[i][j]) {intTMP =T[i][j]; if(i+x-1>n)return; if(j+y-1&GT;M)return;  for(intIi=0; ii<x;ii++)                {                     for(intjj=0; jj<y;jj++) {T[i+ii][j+jj]-=tmp; if(t[i+ii][j+jj]<0)return; } }}}} ans= sum/(x*y);}intMain () {n=read (), m=read ();  for(intI=1; i<=n;i++)         for(intj=1; j<=m;j++) M[i][j]=read (), sum+=M[i][j];  for(inti=n;i>=1; i--)    {         for(intj=m;j>=1; j--)        {            if(sum% (i*j) = =0&&ans>sum/(i*j)) {work (I,J); }}} printf ("%d\n", ans);}

Bzoj 2241: [SDOI2011] hit the ground rat violence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.