显示代码纯文本
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
struct arr{
int k,p,a;
}a[21];
int b[21][21],f[1200000];
int n,B;
int lowbit(int x){
return x&(-x);
}
int award(int score,int ii){
for (int i = 0; i < B; i++){
if (score >= a[i].p && a[i].k == ii) score += a[i].a;
}
return score;
}
int main(){
freopen("deca.in", "r", stdin);
freopen("deca.out", "w", stdout);
int i,ii,tem,nn,j;
scanf("%d%d",&n,&B);
for (i = 0; i < B; i++){
scanf("%d%d%d",&a[i].k,&a[i].p,&a[i].a);
a[i].k--;
}
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
scanf("%d",&b[i][j]);
nn = 1<<n;
for (i = 1; i < nn; i++){
tem = i;
ii = 0;
while (tem){
ii++;
tem -= lowbit(tem);
}
for (j = 0; j < n; j++){
if (i&(1<<j)){
f[i] = max(f[i],f[i^(1<<j)]+b[j][ii-1]);
}
}
f[i] = award(f[i],ii-1);
}
printf("%d",f[nn-1]);
return 0;
}