"bzoj2241" [SDOI2011] hit the ground rat violence + WTF

Source: Internet
Author: User
Tags gopher

2241: [SDOI2011] hit the ground rat
Time Limit:10 Sec Memory limit:512 MB
submit:1069 solved:679
[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 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 Input
7 ·

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

title link : http://www.lydsy.com/JudgeOnline/problem.php?id=2241

Test Instructions : Chinese question.

Ideas :
Enumeration I*j is (N^6), plus a variety of optimization and chaos can be;
1. First the size of the hammer first row (column) enumeration, sieve principle Shear Branch;

        if(sum%i!=0||!can(i,1))        {            for(int j=i;j<=n;j+=i)            lin[j]=-1;        }

2. Criteria for judging the search:

if(sum/(i*j)>anscontinue;

Code :

#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace Std;int Ma[101][101];inttmp[101][101];intNm;intt[101];intlin[101];introw[101];intSumintAns;bool Can (int x,int y){ for(intI=1; i<=n;i++) for(intj=1; j<=m; j + +) tmp[i][j]=MaI [j]; for(intI=1; i<=n;i++) for(intj=1; j<=m; j + +)if(Tmp[i][j]) {if(i+x>n+1|| j+y>m+1)return 0;intTT=TMP[I][J]; for(intii=i;ii<i+x; ii++) { for(intjj=j;jj<j+y; jj++) {tmp[ii][jj]-=tt;if(tmp[ii][jj]<0)return 0; }}} ans=sum/(x*y);return 1;}intMain () {scanf ("%d%d",&n,&m); for(intI=1; i<=n;i++) for(intj=1; j<=m; j + +) {scanf ("%d",&MaI        [j]); sum+=MaI    [j]; } Can (1,1); for(intI=2; i<=n;i++)if(!lin[i]) {if(Sum%i!=0||! Can (I,1))        { for(intJ=i;j<=n;j+=i) lin[j]=-1; }    } for(intI=2; i<=m; i++)if(!row[i]) {if(Sum%i!=0||! Can1, i)) { for(intj=i;j<=m; j+=i) row[j]=-1; }    } for(intI=2; i<=n;i++)if(!lin[i]) { for(intIi=2; ii<=m; ii++) T[ii]=row[ii]; for(intj=2; j<=m; j + +)if(!t[j]) {if(Sum/(i*j) >ans)Continue;if(Sum%(I*j)!=0||! Can (I,J)) for(intk=j;k<=m; k+=j) t[k]=-1; }    }printf("%d\ n", ans);}

"bzoj2241" [SDOI2011] hit the ground rat violence + WTF

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.