显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n,m,k,ans=0x3f3f3f3f;
int cw[105],s[25],t[25],c[25],a[25],b[25],p[25],v[25];
bool f(){
for(int i=1;i<=k;i++){
if(cw[i]>0){
return false;
}
}
return true;
}
void dfs(int dep,int s){
if(dep>m){
if(f()){
ans=min(ans,s);
}
return;
}
dfs(dep+1,s);
for(int i=a[dep];i<=b[dep];i++){
cw[i]-=p[dep];
}
dfs(dep+1,s+v[dep]);
for(int i=a[dep];i<=b[dep];i++){
cw[i]+=p[dep];
}
}
int main(){
freopen("kongtiao.in","r",stdin);
freopen("kongtiao.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>s[i]>>t[i]>>c[i];
k=max(k,t[i]);
for(int j=s[i];j<=t[i];j++){
cw[j]+=c[i];
}
}
for(int i=1;i<=m;i++){
cin>>a[i]>>b[i]>>p[i]>>v[i];
}
dfs(1,0);
cout<<ans<<endl;
return 0;
}