显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int u=30;
int s[u][u],a[u][u],p[u][u];
int sum[u] = {0};
int ans,n,b;
int f[1<<21 + 1];
int lowbit(int y){
return (-y)&y;
}
void DP(){
memset(f,0,sizeof(f));
for (int i=1; i<(1<<n); i++){
int w=0,cc=i;
while (cc) {
w++;
cc-=lowbit(cc);
}
for (int j=1; j<=n; j++)
if (i&(1<<(j-1))) {
f[i]=max(f[i],f[i^(1<<(j-1))]+s[j][w]);
}
int temp = 0;
for (int j = 1; j <= sum[w]; j++){
if (f[i] >= p[w][j]) temp += a[w][j];
}
f[i] += temp;
}
ans=f[(1<<n)-1];
}
int main(){
freopen("deca.in","r",stdin);
freopen("deca.out","w",stdout);
scanf("%d%d",&n,&b);
int i;
for (i=1; i<=b; i++){
int temp,x,y;
scanf("%d%d%d",&temp,&x,&y);
p[temp][++sum[temp]]=x;
a[temp][sum[temp]]=y;
}
for (i=1; i<=n; i++)
for (int j=1; j<=n; j++)
scanf("%d",&s[i][j]);
DP();
printf("%d\n",ans);
return 0;
}