time limit per test
1.0 s
memory limit per test
1024 MB
input
standard input
output
standard output
Music festivals should be fun, but some of them become so big that cause headache for the goers. The problem is that there are so many good attractions playing in so many stages that the simple task of choosing which shows to watch becomes too complex.
To help goers of such festivals, Fulano decided to create an app that, after evaluating the songs heard on the users' favorite streaming services, suggests which shows to watch so that there is no other combination of shows that is better according to the criteria described below:
Unfortunately the beta version of app received criticism, because users were able to think of better selections than those suggested. Your task in this problem is to help Fulano and write a program that, given the descriptions of the shows happening in each stage, calculates the ideal list of artists to the user.
The displacement time between the stages is ignored; therefore, as long as there is no intersection between the time ranges of any two chosen shows, it is considered that it is possible to watch both of them. In particular, if a show ends exactly when another one begins, you can watch both of them.
Input
The first line contains an integer 1≤N≤101≤N≤10 representing the number of stages. The following NN lines describe the shows happening in each stage. The ii-th of which consists of an integer Mi≥1Mi≥1, representing the number of shows scheduled for the ii-th stage followed by MiMi show descriptions. Each show description contains 3 integers ij,fj,ojij,fj,oj (1≤ij Output Your program must produce a single line with an integer representing the total number of songs previously heard from the chosen artist, or −1 if there is no valid solution. Examples input Copy output Copy input Copy output Copy 点我传送 有n个舞台,每个舞台上有m场表演,每场表演有开始时间si 结束时间ei 以及一个权值wi,现在要求每场舞台的表演至少都要选择一场,其他随意选择,要观看的保证时间不重叠。(题目保证同一舞台的表演不会有重叠)。 询问最大能得到的权值是多少。 由于n的范围只有10,所以想到用二进制来表达选择表演的状态,1表示在这个舞台至少选择了一场,0则表示没有选择。 开始时间和结束时间范围太大,首先需要离散化,这样就可以处理出多个小区间,选择用vector来记录该区间达到的右端r 、该区间属于的舞台fr 、该区间的权值val 。 用dp[ i ][ j ] 表示选择到 i 位置处状态为 j 时的最大权值。 状态转移: dp[ now.r ][ k |(1<<(now.fr-1))]=max(dp[ now.r ][ k |(1<<(now.fr-1))],mic[ i ] [ j ].val+dp[ i ][ k ]) 。 其中k表示当前枚举到的状态。如果 k 不等于0的时候,表示之前一定选择过了区间,所以如果此时dp值为零,表示之前的状态还没有出现过,就不能进行更新。 当然为了保证中间状态不丢失,还需要 dp[ i ] [ k ]=max(dp[ i ][ k ],dp[ i-1 ][ k ]) 来记录之前的状态。 3
4 1 10 100 20 30 90 40 50 95 80 100 90
1 40 50 13
2 9 29 231 30 40 525
859
3
2 13 17 99 18 19 99
2 13 14 99 15 20 99
2 13 15 99 18 20 99
-1
一、原题地址
二、大致题意
三、大致思路
四、代码
#include