"Enumeration" "Sdoi 2011" "Bzoj 2241" hit the Hamster

Source: Internet
Author: User
Tags gopher

2241: [SDOI2011] hit the ground rat
Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 877  Solved: 557

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:由于你可以把锤子的大小设置为1*1,因此本题总是有解的。

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 Input

3 31 2 12 4 21 2 1

Sample Output

4

"Sample description"

Use 2*2 hammers, waving once at the top left, bottom left, top right, and right.

"Data size and conventions"

For 100% of data, 1<=m,n<=100, other data is not less than 0, not greater than 10^5

Exercises

Violent enumeration area, because each hit is equal to let all the hamster and minus the area, so judge whether it can be divisible, and then judge whether it is feasible.

Code:

#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using namespace STD;#define Nstructa{intR,c,s;} B[n*n];intn,m,s=0, num=0, A[n][n],d[n][n];intIn () {intx=0;CharCh=getchar (); while(ch<' 0 '|| Ch>' 9 ') Ch=getchar (); while(ch>=' 0 '&& ch<=' 9 ') x=x*Ten+ch-' 0 ', Ch=getchar ();returnx;}BOOLCMP (A x,a y) {returnX.S&GT;Y.S;}BOOLJudge (A now) {if(S%NOW.S)return false;intr=now.r,c=now.c,x=1, y=1; for(intI=1; i<=n; i++) for(intj=1; j<=m; J + +) D[i][j]=a[i][j]; while(X<=n && y<=m) {if(!d[x][y]) {if(y<m) y++;Elsex++,y=1;Continue; }intK=d[x][y];if(x+r-1>n | | y+c-1&GT;M)return false; for(inti=x;i<=x+r-1; i++) for(intj=y;j<=y+c-1; j + +) {if(d[i][j]>=k) d[i][j]-=k;Else return false; }    }return true;}intMain () {n=in (), M=in (); for(intI=1; i<=n; i++) for(intj=1; j<=m; J + +) A[i][j]=in (), s+=a[i][j]; for(intI=1; i<=n; i++) for(intj=1; j<=m;            J + +) {A x; x.r=i,x.c=j,x.s=i*j;        B[++num]=x; } sort (b +1, b+num+1, CMP); for(intI=1; i<=num; i++)if(Judge (B[i])) {printf("%d\n", S/B[I].S); Break; }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Enumeration" "Sdoi 2011" "Bzoj 2241" hit the Hamster

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.