比赛 |
20140414 |
评测结果 |
AAATTTTTTT |
题目名称 |
奶牛的十项全能 |
最终得分 |
30 |
用户昵称 |
◆半城烟沙灬為你打天下 |
运行时间 |
7.001 s |
代码语言 |
C++ |
内存使用 |
0.32 MiB |
提交时间 |
2014-04-14 11:21:01 |
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int a[30],b[30],c[30],d[30],map[30][30],father[30];
int n,m,ans;
void dfs(int x)
{
if (x==n+1)
{
d[0]=0;
for (int i=1;i<=n;i++) d[i]=d[i-1]+map[father[i]][i];
int tt=d[n];
for (int i=1;i<=m;i++)
{
if (d[a[i]]>=b[i]) tt=tt+c[i];
}
ans=max(ans,tt);
return;
}
for (int i=1;i<=n;i++)
{
if (father[i]) continue;
father[i]=x;
dfs(x+1);
father[i]=0;
}
}
int main()
{
freopen("deca.in","r",stdin);
freopen("deca.out","w",stdout);
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++)
{
scanf("%d%d%d",&a[i],&b[i],&c[i]);
}
for (int i=1;i<=n;i++)
{
for (int j=1;j<=n;j++)
{
scanf("%d",&map[i][j]);
}
}
ans=0;
memset(father,0,sizeof(father));
dfs(1);
printf("%d",ans);
}