记录编号 96741 评测结果 AAAAAAAAAA
题目名称 [USACO Feb14] 奶牛的十项全能 最终得分 100
用户昵称 GravatarFF_Sky||幻 是否通过 通过
代码语言 C++ 运行时间 0.810 s
提交时间 2014-04-14 18:07:09 内存使用 4.87 MiB
显示代码纯文本
#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;
}