No.679 Mysterious Market
タグ : / 解いたユーザー数 101
作問者 :
horiesiniti
/ テスター :
はむこ
Problem Statement
The Mysterious Market is a supermarket consisting of a single straight aisle.
In this market, each product is assigned one number from $1$ to $n$, and no two or more of the same product exist.
From the entrance to the exit of the aisle, $n$ shelves are placed in order along the aisle.
Each shelf can hold one kind of product among products $1$ to $n$.
In the Mysterious Market, customers must visit the shelves in order from the entrance to the exit of the aisle without going back, and the following mysterious rules exist.
- If $h_{(i,1)}$ to $h_{(i,r_i)}$ are all in the basket, the customer must put product $g_i$ into the basket when passing in front of its shelf.
- A product with no such condition must always be put into the basket when passing in front of its shelf.
When the products are arranged appropriately, what is the maximum number of kinds of products that customers can be made to put into their baskets?
Input
$n$ $m$
$g_1$ $r_1$
$h_{(1,1)}$ $\dots$ $h_{(1,r_1)}$
$\vdots$
$g_i$ $r_i$
$h_{(i,1)}$ $\dots$ $h_{(i,r_i)}$
$\vdots$
$g_m$ $r_m$
$h_{(m,1)}$ $\dots$ $h_{(m,r_m)}$
$n$ is the number of kinds of products and the number of shelves. $m$ is the number of kinds of products that must be put into the basket when certain specified products are all in the shopping basket.
$1 \le n \le 500$
$0 \le m \le n$
$g_i$ $r_i$
$g_i$ is the product number, and $r_i$ is the number of products required to make the customer put $g_i$ into the shopping basket.
$1 \le g_i \le n$
$1 \le r_i \le 32$
$h_{(i,1)}$ $\dots$ $h_{(i,r_i)}$
$1 \le h_{(i,j)} \le n$
This is the list of goods required to make the customer put product $g_i$ into the shopping basket. If the customer has put all of $h_{(i,1)}$ to $h_{(i,r_i)}$ into the shopping basket by the time they reach that shelf, the customer must put product $g_i$ into the shopping basket.
You may assume that there are no duplicates among $h_{(i,j)}$ with the same $i$.
You may also assume that $g_i = g_j$ does not occur.
Also, $g_i = h_{(i,j)}$ does not occur.
Output
Output the maximum number of kinds of products that customers can be made to put into their baskets when the products are arranged appropriately. Print a newline at the end.
Sample
Sample 1
Input
10 8 7 1 8 10 1 3 9 3 3 4 10 5 2 8 4 2 3 7 1 10 4 2 7 6 6 2 1 3 1 2 7 3
Output
10
By arranging them appropriately, customers can be made to put all the products into their baskets.
Sample 2
Input
8 7 2 1 1 8 1 1 3 2 2 8 4 1 3 5 2 3 6 6 3 3 4 7 7 1 5
Output
5
When arranged appropriately, customers can be made to put at most 5 products into their baskets.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。