Bzoj 2241: [SDOI2011] hit the gopher (Mob + branch)

Source: Internet
Author: User
Tags gopher

2241: [SDOI2011] hit Gopher time limit: Sec Memory Limit: MB
Submit: 1098 Solved: 691
[Submit] [Status] [Discuss] 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 game Hammer can only hit one hamster at a time, if more than a hamster at the same time, the player can only be repeated by wielding a hammer to knock out all the gopher. 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 m*n Span lang= "en-US" >r*c All hamster holes in the area. But the modified Hammer has one drawback: every time the hammer is waved, for this r*c All the burrows in the area, The hammer will knock out exactly one gopher. That is, in the area where the hammer is covered, each burrow must have at least 1 1 then this burrow will only have 1 Span style= "font-family: Arial" > Only rats were knocked out, so every time you wield a hammer, there is exactly r*c r Span lang= "en-US" >c

You can change the size of the hammer arbitrarily (that is, you can specify R and the C size), but the work of a modified hammer can only be done in front of the hamster (i.e. you can not knock 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 , so there is always a solution to the subject.

Input

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

below M row per row N a positive integer describing the map, with each number representing the number of hamsters in the burrow in 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
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
HINT

Source

First round Day1

[Submit] [Status] [Discuss]

Solution: This problem is a linear sieve + second-order differential, but I do not, in fact, this problem can be used to search and reduce the branch to achieve.

We find that no matter how large the hammer is, there is always a need to fight, so that only one place becomes 0, the hammer can move backwards. Then we can match between us from the upper left corner.

Note that the initial value is sum (the total number of squares). In the case of violence, the size of the hammer is enumerated only when sum/(I*J) is used, and the optimal value can be added to reduce the number of sticks. If the value of a lattice becomes negative, then the scheme needs to be discarded.

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Cmath>using namespace Std;int n,m,ans;int a[120][120],t[120][120],sum;void dfs (int x,int y) {for (int i=1;i<=n;i++ ) for (int j=1;j<=m;j++) T[i][j]=a[i][j];int k=0;for (int. i=1;i<=n;i++) for (int j=1;j<=m;j++)  if (T[i][j]) c1/>{    if (K>=ans)  return;    int tmp=t[i][j];    if (i+x-1>n| | J+Y-1>M) return;    for (int l=0;l<x;l++) for     (int u=0;u<y;u++)      {      t[i+l][j+u]-=tmp;      if (t[i+l][j+u]<0)  return;      }    k+=tmp;   } Ans=min (K,ans);   } int main () {scanf ("%d%d", &n,&m), for (Int. i=1;i<=n;i++) for (int j=1;j<=m;j++)  scanf ("%d", &a[i] [j]), sum+=a[i][j];ans=sum;for (int i=n;i>=1;i--) for (int j=m;j>=1;j--)  if (sum% (i*j) ==0&&sum/(i* j) <ans)   dfs (I,J);p rintf ("%d", ans);


Bzoj 2241: [SDOI2011] hit the gopher (Mob + branch)

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.