ARC068F Solitaire <计数DP>
Problem
Solitaire
Timelimit:2Sec
Memorylimit:256MB
Statement
Snuke has decided to play with N cards and a deque (that is, a double-ended queue). Each card shows an integer from 1 through N, and the deque is initially empty.
Snuke will insert the cards at the beginning or the end of the deque one at a time, in order from 1 to N. Then, he will perform the following action N times: take out the card from the beginning or the end of the deque and eat it.
Afterwards, we will construct an integer sequence by arranging the integers written on the eaten cards, in the order they are eaten. Among the sequences that can be obtained in this way, find the number of the sequences such that the Kth element is 1. Print the answer modulo 109+7.
Constraints
1≤K≤N≤2000
Input
The input is given from Standard Input in the following format:
NK
Output
Print the answer modulo 109+7.
BZOJ4002【JLOI2015】有意义的字符串 <线性齐次递推>
BZOJ2001【HNOI2010】城市建设 < CDQ分治+MST >
Problem
【HNOI2010】城市建设
TimeLimit:20Sec
MemoryLimit:162MB
Description
PS国是一个拥有诸多城市的大国,国王Louis为城市的交通建设可谓绞尽脑汁。Louis可以在某些城市之间修建道路,在不同的城市之间修建道路需要不同的花费。Louis希望建造最少的道路使得国内所有的城市连通。但是由于某些因素,城市之间修建道路需要的花费会随着时间而改变,Louis会不断得到某道路的修建代价改变的消息,他希望每得到一条消息后能立即知道使城市连通的最小花费总和,Louis决定求助于你来完成这个任务。
Input
第一行三个整数N,M,Q,分别表示城市的数目,可以修建的道路个数,收到的消息个数。
接下来M行,第i+1行有三个用空格隔开的整数Xi,Yi,Zi(1≤Xi,Yi≤n,0≤Zi≤5×107),表示在城市Xi与城市Yi之间修建道路的代价为Zi。
接下来Q行,每行包含两个数k,d,表示输入的第k个道路的修建代价修改为d(即将Zk修改为d)。
Output
Q行,第i行输出得知前i条消息后使城市连通的最小花费总和。
BZOJ3157 国王奇遇记 <倍增>
BZOJ3516 国王奇遇记加强版 <扰动法>
HR34E Magic Cards <状压>
Problem
Magic Cards
by Birjik
Description
Birzhan has n cards, numbered from 1 to n. Every card has each number from 1 to m written on it. Some numbers exist on the front side of the card and some on the back side. No number exists on both the sides of a card at the same time. These cards are placed on the table in a row such that only one side is visible. Birzhan is allowed to flip them any number of times.
Now, Birzhan has to answer q queries each of them consisting of two integers l and r (1≤l≤r≤n). We define f(l,r) as the sum of the squares of every integer from 1 to m if it exists on the visible side of any card numbered from l to r. Given that Birzhan can flip any number of cards any number of times, find and print the maximum value of f(l,r).
For example, given 3 cards and m=5 we have the as follows:-
Now, for l=1 and r=2. We have 1,2,4,5 on the two cards, the sum of their squares is 46.
If we flip the first card, we get 3,4,5, the sum of their squares is 50.
And, if we flip both cards, we get 1,2,3,4,5, the sum of their squares is 55
Hence, the maximum value of f(1,2) in the above case is 55.
Input Format
The first line contains three space-separated integers, n, m, and q, denoting the number of cards, what numbers written on each card, and the number of queries, respectively.
Each of the next n lines describes the cards. On each line, the first number is xi, denoting the count of numbers written on the visible side of the ith card. Next xi space-separated unique integers represent the numbers written on the visible side of that card, each between 1 and m.
Next q lines contain two space-separated integers, l and r, describing the query mentioned above.
Constraints
- 1≤n×m,q≤106
- 0≤xi≤m
- 1≤l≤r≤n
Output Format
Print the maximum value of f(l,r) for each query.
BZOJ4001【TJOI2015】概率论 <生成函数>
CF40E Number Table <计数>
Problem
Number Table
TimeLimit:2seconds
MemoryLimit:216megabytes
Description
As it has been found out recently, all the Berland’s current economical state can be described using a simple table n×m in size. n ― the number of days in each Berland month, m ― the number of months. Thus, a table cell corresponds to a day and a month of the Berland’s year. Each cell will contain either 1, or −1, which means the state’s gains in a particular month, on a particular day. 1 corresponds to profits, −1 corresponds to losses. It turned out important for successful development to analyze the data on the state of the economy of the previous year, however when the treasurers referred to the archives to retrieve the data, it turned out that the table had been substantially damaged. In some table cells the number values had faded and were impossible to be deciphered. It is known that the number of cells in which the data had been preserved is strictly less than max(n,m). However, there is additional information ― the product of the numbers in each line and column equaled −1. Your task is to find out how many different tables may conform to the preserved data. As the answer to the task can be quite large, you have to find it modulo p.
Input
The first line contains integers n and m (1≤n,m≤1000). The second line contains the integer k (0≤k<max(n,m)) ― the number of cells in which the data had been preserved. The next k lines contain the data on the state of the table in the preserved cells. Each line is of the form a b c
, where a (1≤a≤n) ― the number of the table row, b (1≤b≤m) ― the number of the column, c ― the value containing in the cell (1 or −1). They are numbered starting from 1. It is guaranteed that no two lines with same a and b values exist. The last line contains an integer p (2≤p≤109+7).
Output
Print the number of different tables that could conform to the preserved data modulo p.