现在的位置: 首页 > 综合 > 正文

【gcj 2014 r2】河流、trie sharding 题目

2018年04月12日 ⁄ 综合 ⁄ 共 4931字 ⁄ 字号 评论关闭

https://code.google.com/codejam/contest/3014486/dashboard#s=p3


 Problem C. Don't Break The Nile

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start
Guide
 to get started.
Small input
10 points
Large input
20 points

Problem

Aliens have landed. These aliens find our Earth's rivers intriguing because their home planet has no flowing water at all, and now they want to construct their alien buildings in some of Earth's rivers. You have been tasked with making sure their buildings
do not obstruct the flow of these rivers too much, which would cause serious problems. In particular, you need to determine what the maximum flow that the river can sustain is, given the placement of buildings.

The aliens prefer to construct their buildings on stretches of river that are straight and have uniform width. Thus you decide to model the river as a rectangular grid, where each cell has integer coordinates (XY; 0 ≤ X < W and
0 ≤ Y < H). Each cell can sustain a flow of 1 unit through it, and the water can flow between edge-adjacent cells. All the cells on the south side of the river (that is with y-coordinate equal to 0) have an implicit incoming
flow of 1. All buildings are rectangular and are grid-aligned. The cells that lie under a building cannot sustain any flow. Given these constraints, determine the maximum amount of flow that can reach the cells on the north side of the river (that is with
y-coordinate equal to H-1).

Input

The first line of the input gives the number of test cases, TT test cases follow. Each test case will begin with a single line containing three integers, W, the width of the river,H, the
height of the river, and B, the number of buildings being placed in the river. The next B lines will each contain four integers, X0Y0X1, and Y1X0Y0 are
the coordinates of the lower-left corner of the building, and X1Y1 are the coordinates of the upper-right corner of the building. Buildings will not overlap, although two buildings can share an edge.

Output

For each test case, output one line containing "Case #x: m", where x is the test case number (starting from 1) and m is the maximum flow that can pass through the river.

Limits

1 ≤ T ≤ 100.
0 ≤ X0 ≤ X1 < W.
0 ≤ Y0 ≤ Y1 < H.

Small dataset

3 ≤ W ≤ 100.
3 ≤ H ≤ 500.
0 ≤ B ≤ 10.

Large dataset

3 ≤ W ≤ 1000.
3 ≤ H ≤ 108.
0 ≤ B ≤ 1000.

Sample


Input 
 

Output 
 
2
3 3 2
2 0 2 0
0 2 0 2
5 6 4
1 0 1 0
3 1 3 3
0 2 1 3
1 5 2 5

Case #1: 1
Case #2: 2

Here are visual representations of the two test cases in the sample input:

   

网络流问题。

但是大数据h很大,该怎么处理?必然有。


Problem D. Trie Sharding

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start
Guide
 to get started.
Small input
9 points
Large input
30 points

Problem

A set of strings S can be stored efficiently in a trie. A trie is a rooted tree that has one node for every prefix of every string in S, without duplicates.

For example, if S were "AAA", "AAB", "AB", "B", the corresponding trie would contain 7 nodes corresponding to the prefixes "", "A", "AA", AAA", "AAB", "AB", and "B".

I have a server that contains S in one big trie. Unfortunately, S has become very large, and I am having trouble fitting everything in memory on one server. To solve this problem, I want to switch to storing S across N separate
servers. Specifically, S will be divided up into disjoint, non-empty subsets T1T2, ..., TN, and on each server i, I will build a trie containing just the
strings in Ti. The downside of this approach is the total number of nodes across all N tries may go up. To make things worse, I can't control how the set of strings is divided up!

For example, suppose "AAA", "AAB", "AB", "B" are split into two servers, one containing "AAA" and "B", and the other containing "AAB", "AB". Then the trie on the first server would need 5 nodes ("", "A", "AA", "AAA", "B"), and the trie on the second server
would also need 5 nodes ("", "A", "AA", "AAB", "AB"). In this case, I will need 10 nodes altogether across the two servers, as opposed to the 7 nodes I would need if I could put everything on just one server.

Given an assignment of strings to N servers, I want to compute the worst-case total number of nodes across all servers, and how likely it is to happen. I can then decide if my plan is good or too risky.

Given S and N, what is the largest number of nodes that I might end up with? Additionally, how many ways are there of choosing T1T2, ..., TN for
which the number of nodes is maximum? Note that the N servers are different -- if a string appears in Ti in one arrangement and in Tj (i != j)
in another arrangement, then the two arrangements are considered different. Print the remainder of the number of possible arrangements after division by 1,000,000,007.

Input

The first line of the input gives the number of test cases, TT test cases follow. Each test case starts with a line containing two space-separated integers: M and NM lines
follow, each containing one string in S.

Output

For each test case, output one line containing "Case #iX Y", where i is the case number (starting from 1), X is the worst-case number of nodes in all the tries combined, and Y is
the number of ways (modulo 1,000,000,007) to assign strings to servers such that the number of nodes in all N servers are X.

Limits

1 ≤ T ≤ 100.
Strings in S will contain only upper case English letters.
The strings in S will all be distinct.
N ≤ M

Small dataset

1 ≤ M ≤ 8 
1 ≤ N ≤ 4 
Each string in S will have between 1 and 10 characters, inclusive.

Large dataset

1 ≤ M ≤ 1000 
1 ≤ N ≤ 100 
Each string in S will have between 1 and 100 characters, inclusive.

Sample


Input 
 

Output 
 
2
4 2
AAA
AAB
AB
B
5 2
A
B
C
D
E

Case #1: 10 8
Case #2: 7 30

抱歉!评论已关闭.