#P13442. [GCJ 2009 #2] Stock Charts

    ID: 15316 远端评测题 2000~3000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2009网络流二分图Google Code Jam

[GCJ 2009 #2] Stock Charts

题目描述

You're in the middle of writing your newspaper's end-of-year economics summary, and you've decided that you want to show a number of charts to demonstrate how different stocks have performed over the course of the last year. You've already decided that you want to show the price of nn different stocks, all at the same kk points of the year.

A simple chart of one stock's price would draw lines between the points (0,price0)(0, \text{price}_0), (1,price1)(1, \text{price}_1), ..., (k1,pricek1)(k-1, \text{price}_{k-1}), where pricei\text{price}_i is the price of the stock at the iith point in time.

In order to save space, you have invented the concept of an overlaid chart. An overlaid chart is the combination of one or more simple charts, and shows the prices of multiple stocks (simply drawing a line for each one). In order to avoid confusion between the stocks shown in a chart, the lines in an overlaid chart may not cross or touch.

Given a list of nn stocks' prices at each of kk time points, determine the minimum number of overlaid charts you need to show all of the stocks' prices.

输入格式

The first line of input will contain a single integer TT, the number of test cases. After this will follow TT test cases on different lines, each of the form:

nn kk

price0,0\text{price}_{0,0} price0,1\text{price}_{0,1} ... price0,k1\text{price}_{0,k-1}

price1,0\text{price}_{1,0} price1,1\text{price}_{1,1} ... price1,k1\text{price}_{1,k-1}

...

pricen1,0\text{price}_{n-1,0} pricen1,1\text{price}_{n-1,1} ... pricen1,k1\text{price}_{n-1,k-1}

Where pricei,j\text{price}_{i,j} is an integer, the price of the iith stock at time jj.

输出格式

For each test case, a single line containing "Case #XX: YY", where XX is the number of the test-case (1-indexed) and YY is the minimum number of overlaid charts needed to show the prices of all of the stocks.

3
3 4
1 2 3 4
2 3 4 6
6 5 4 3
3 3
5 5 5
4 4 6
4 5 4
5 2
1 1
2 2
5 4
4 4
4 1
Case #1: 2
Case #2: 3
Case #3: 2

提示

Limits

  • 1T1001 \leq T \leq 100
  • 2k252 \leq k \leq 25
  • 0pricei,j10000000 \leq \text{price}_{i,j} \leq 1000000

Small Input

  • Time limit: 20 2 seconds.
  • 1n161 \leq n \leq 16

Large Input

  • Time limit: 30 3 seconds.
  • 1n1001 \leq n \leq 100