CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » February 2010 Contest » The Mine Field

The Mine Field

Problem code: M1

  • All Submissions

All submissions for this problem are available.

It's 2012. The times of peace are over. The Trojan Kingdom has just declared war on Byteland! As part of a massive defense plan against the Trojans, the Bytelandian Ministry of Defense (BMoD) wants to lay mines on a field near the borderline of the country.

The field has the form of a MxN rectangular grid divided into MxN unit-square cells. It is only possible to plant mines on some cells, and the number of mines on a cell cannot exceed one.

The objective is obviously to lay as many mines as possible. However, the BMoD does not want any two adjacent cells to both have mines, because such a situation would be dangerous: one mine being triggered could lead to a chain of explosions! Two cells are adjacent if they share a common edge.

Johnny, the most renowned computer scientist in Byteland, needs to compute the maximum number of mines that could be planted on the field, and the number of different ways in which these mines could be planted.

Hurry up and help Johnny save his beloved country!

Input

The first line contains T (about 15), the number of test cases. Then T test cases follow. Each test case has the following form.

The first line contains two numbers M and N representing the size of the field (1 <= M, N <= 20).

Each line in the next M lines contains N characters. Each character is either '.' or '*' representing the status of a cell in the field. A character '.' represents an empty cell (i.e. it is possible to lay a mine on that cell), while a character '*' represents a blocked cell (i.e. there are obstacles on that cell which prevent mines from being laid on it).

Input for successive test case is separated by a blank line.

Output

For each test case, print two numbers on a line. The first number is the maximum number of mines that could be planted on the field. The second number is the number of ways to plant the maximum number of mines on the field, modulo 151109.

Example

Input:
2
2 3
...
.*.

3 3
...
.*.
...

Output:
3 1
4 2


Author:
Date Added: 15-01-2010
Time Limit: 4 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

bound on m & n are missing?

gautamverma @ 1 Feb 2010 03:20 PM

bound on m & n are missing?

Well, they're not missing;

triplem @ 1 Feb 2010 03:55 PM

Well, they're not missing; they just still haven't fixed the recurring problem of inequality signs not showing up. 1 M,N 20 means 1 <= M,N <= 20.

Fixed.

admin @ 1 Feb 2010 04:13 PM

Fixed.

if say all the cells are

sumanta.dey2001 @ 2 Feb 2010 10:53 AM

if say all the cells are bloked i.e. you can not place any mines ,

what will be the expected output

max mine :- 0

number of ways :- 0

please reply

Hi I am getting Runtime error

angel_programmer @ 2 Feb 2010 11:08 AM

Hi

I am getting Runtime error (NZEC).

Language: Java

 

Any idea?

Why do you think you would be

triplem @ 2 Feb 2010 01:50 PM

Why do you think you would be given hints? You won't.

@xyz I don't think that's

Brian Drake @ 2 Feb 2010 03:51 PM

@xyz I don't think that's right but since this is a competition I won't say any more.

@paras See the FAQ. It probably means that your program is throwing an exception somewhere. Unless the judge is broke, you won't get any more information than that.

Brian my case is an

sumanta.dey2001 @ 2 Feb 2010 04:15 PM

Brian my case is an absolutely corner case,

this should be specified in problem statement .

it is like base case of an recursion, ( think f(n) = f(n - 1) + f(n -2) , would you be able to calculate if you have not been provided with f(0) and f(1))

please specify what is the expected behavior when you can not able to inset a single mine.

thanks

 

@XYZ: your question teeters

pieguy @ 3 Feb 2010 12:34 AM

@XYZ: your question teeters on the line between hints and problem statement clarification.  I'm inclined not to answer your question because it's not an ambiguous case.  Read the problem statement carefully and hopefully the answer will come.

can any one tell me the cases

satyendra @ 3 Feb 2010 07:47 PM

can any one tell me the cases of 2nd answer 4mines and 2 ways one way is (0,0) ,(2,0),(0,2)and(2,2)if matrix is a[3][3] if i understand wrong can any one elaborate a little

@satyendra other is (0,1)

ramthegreatcv @ 4 Feb 2010 01:43 AM

@satyendra other is (0,1) (1,0) (1,2) (2,1)

Looks like Stephen cut the

jcomeau_ictx @ 4 Feb 2010 12:08 PM

Looks like Stephen cut the knot... nice job!

@everybody pls tell me is

dabbcomputers @ 4 Feb 2010 06:31 PM

@everybody

pls tell me is block 00 and 11 are adjacent...

pls help...

in 20*20 grid there is max

ajaybilotia @ 4 Feb 2010 07:38 PM

in 20*20 grid there is max mine is 200..than why is mode 151109

is it compulsory that we have

bhavesh.j25 @ 7 Feb 2010 06:20 PM

is it compulsory that we have to use  .   &  * ...y cant we use any alphabets or numbers

lol this is funny .. i am

foofoo @ 9 Feb 2010 07:05 PM

lol this is funny .. i am getting an Runtime error (OTHER) despite checking many times? Would it be too much to ask for error messages or the admin thinks ill print the test cases to stderr ? lol

m newbie hereits my first

anant4coding @ 10 Feb 2010 04:47 PM

m newbie here

its my first time

can u please tell me how to take input

whether as .txt file or somhw else???

 

anant mittal // by Standard

azurespace @ 11 Feb 2010 06:57 AM

anant mittal // by Standard Input/Output

Anyway It seems like a

azurespace @ 11 Feb 2010 07:01 AM

Anyway It seems like a typical problem tgat can be solved memoization, what I should do is to determine how to represent the status. I have an rough idea.. but I will think more because there should be a better way to do that.

Please don't discuss

triplem @ 11 Feb 2010 07:08 AM

Please don't discuss approaches to the problem until the contest is over.

Oops. I thought it was over.

azurespace @ 11 Feb 2010 07:38 AM

Oops. I thought it was over. Sorry.

@anant Please don't post the

Brian Drake @ 11 Feb 2010 01:08 PM

@anant Please don't post the same thing all over the place (although it's understandable that you would want a quick response with the competition about to end). See the FAQ.

@Ajay The maximum number of

Brian Drake @ 11 Feb 2010 01:11 PM

@Ajay The maximum number of mines is, at most, 200, but the number of ways of placing the maximum number of mines might be bigger (I think...I haven't tried this sort of problem before).

@Bhavesh Yes, it is compulsory to use "." and "*", because the problem statement said so.

How long to view solution ?

alok @ 11 Feb 2010 03:38 PM

How long to view solution ?

can anyone provide the

shivmitra @ 3 Mar 2010 10:26 PM

can anyone provide the algorithm for this problem??

Approaches have been

triplem @ 4 Mar 2010 02:51 AM

Approaches have been discussed in the forum.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com