状态压缩dp

 

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:

  • To enjoy the experience as much as possible it is important to watch each of the selected shows from start to end;
  • Going to the festival and not seeing one of the stages is out of the question;
  • To ensure that the selection of artists is compatible with the user, the app counts how many songs from each artist the user had previously listened to on streaming services. The total number of known songs from chosen artists should be the largest possible.

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<fj≤864001≤ij<fj≤86400; 1≤oj≤10001≤oj≤1000), representing respectively the start and end time of the show and the number of songs of the singer performing that were previously heard by the user. The sum of the MiMi shall not exceed 1000.

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

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

Output

859

Input

3
2 13 17 99 18 19 99
2 13 14 99 15 20 99
2 13 15 99 18 20 99

Output

-1

#include <bits/stdc++.h>
using namespace std;
struct node{
    int id,s,e,val;
}a[100010];
vector<node> v[86405];
int dp[100010][1030];
int n,m,cnt;

int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%d",&n);
    for(int j=1;j<=n;j++)
    {
        scanf("%d",&m);
        for(int i=1;i<=m;i++)
        {
            cnt++;
            scanf("%d%d%d",&a[cnt].s,&a[cnt].e,&a[cnt].val);
            a[cnt].id=j-1;
            v[a[cnt].s].push_back(a[cnt]);
        }

    }
    dp[0][0]=0;
    for(int i=1;i<=86400;i++)
    {
        for(int j=0;j<(1<<n);j++)
            dp[i][j]=max(dp[i-1][j],dp[i][j]);
        for(int k=0;k<(1<<n);k++)
        if(dp[i][k]!=-1)
        {
            for(int j=0;j<v[i].size();j++)
            {
                dp[v[i][j].e][k|(1<<v[i][j].id)]=max(dp[v[i][j].e][k|(1<<v[i][j].id)],dp[i][k]+v[i][j].val);
            //    cout<<v[i][j].e<<" "<<(k|(1<<v[i][j].id))<<endl;
            }
        }

    }
    printf("%d\n",dp[86400][(1<<n)-1]);
    return 0;
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值