Programming Challenge 1

News:
Feb 15: Updated the starter codes to read from stdin instead from files.
Feb 1: Experimental release of online judge system.
Jan, 26: Initial posting of this challenge.

Code submission mechanism: Include source code (single file .c/.cpp/.py) in your submission ZIP file to Blackboard. Include your PSID and Submission ID from the on-line judge system. Your code must only read from stdin and write to stdout.

We will be compiling and running your submitted code. We may use test cases that are not given to you.

For your convenience, the starter codes can be found in the sandbox environment: sandbox . You need a Github account to access; it's free of charge. We will be using the same environment and compiler flags to compile your code

Problem 1 (10pt): Backtracking

Online judge/submission link: Problem 1

Given a board with irregular shape, your task is to place chess pieces and make sure no more than 1 chess pieces is placed on the same row or the same column. Output the number of different ways of such placement.

The first line of the input consists of two integers n and k. n means the size of board is n×n and k is the number of chess pieces to be placed. The next n lines describe the shape of the chess board: '#' describes the board region and '.' is the blank region (cannot place chess piece here).

Starter code: pro1.cpp

Example 1

Input:
2 1
.#
#.

Output:
2
        

Example 2

Input:
3 3
#.#
.##
.##
Output:
2
        

Example 3

Input:
4 4
...#
..#.
.#..
#...
Output:
1
        

Problem 2 (10pt): Divide and Conquer

Online judge/submission link: Problem 2

Given an array A, write a program to find the max(A[j]-A[i]) where i < j. If max(A[j]-A[i])<0, output 0. The input will start with an integer n, which indicates the length of the given array. The next line will be the array.

Starter code: pro2.cpp

Example 1

Input:
2
1 5
Output:
4
        

Example 2

Input:
4
1 5 8 2
Output:
7
        

Example 3

Input:
6
8 7 4 3 2 1
Output:
0