记录编号 96717 评测结果 AAAAAAAAAA
题目名称 [USACO Feb14] 奶牛的十项全能 最终得分 100
用户昵称 Gravatar(ˇˍˇ) ~耶稣 是否通过 通过
代码语言 C++ 运行时间 1.403 s
提交时间 2014-04-14 16:50:17 内存使用 14.69 MiB
显示代码纯文本
#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;
}