明显的状压dp, 写得少所以还是不太习惯
好在状态转移很简单
/*author: birdstorm*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#define MAXN 100005
#define N 105
#define INF 1<<30
#define eps 1.0e-10
#define For(i,m,n) for(i=(m);i<n;i++)
#define MAX(x,y) (x)>(y)?(x):(y)
#define MIN(x,y) (x)<(y)?(x):(y)
int dp[MAXN];
main()
{
int i, j, k, L, s, e, n, m, ans, a, tmp;
while(scanf("%d",&n),n){
ans=0;
memset(dp,0,sizeof(dp));
For(i,0,n){
scanf("%d%d",&m,&L);
a=0;
For(j,0,m){
scanf("%d%d",&s,&e);
s-=6; e-=6;
For(k,s,e) a|=1<<k;
}
//int c=1; while(c<=1<<16) printf("%d",c&a?1:0), c<<=1; puts("");
For(j,0,1<<16){
if(!(j&a)){
tmp=j|a;
dp[tmp]=MAX(dp[tmp],dp[j]+L);
ans=MAX(ans,dp[tmp]);
}
}
}
printf("%d\n",ans);
}
return 0;
}