网络流、貌似很多人状态DP >_<
最大权闭合子图
The 36th ACM/ICPC Asia Regional Beijing Site Online Contest
http://acm.bupt.edu.cn/onlinejudge/newoj/showProblem/show_problem.php?problem_id=220
int ins[100];
int val[50][50], comp[50][50];
int main()
{
int n, m;
while(scanf("%d %d", &n, &m) && (n||m))
{
for(int i=1; i<=m; ++i)
scanf("%d", &ins[i]);
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j)
{
scanf("%d", &val[i][j]);
val[i][j] -= ins[j];
}
for(int i=1; i<=n; ++i)
for(int j=1; j<=n; ++j)
scanf("%d", &comp[i][j]);
int sum = 0;
src = 0, des = n*m+n*n*m+1;
init();
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j)
{
if(val[i][j]>0)
{
sum += val[i][j];
addedge(src, i*m-m+j, val[i][j]);
}
else
addedge(i*m-m+j, des, -val[i][j]);
if(j>1)
addedge(i*m-m+j, i*m-m+j-1, INF);
}
for(int i=1; i<=n; ++i)
for(int j=i+1; j<=n; ++j)
for(int k=1; k<=m; ++k)
{
addedge(src, n*m+(i*n-n+j)*m-m+k, comp[i][j]);
addedge(n*m+(i*n-n+j)*m-m+k, i*m-m+k, INF);
addedge(n*m+(i*n-n+j)*m-m+k, j*m-m+k, INF);
sum += comp[i][j];
}
N = des;
int res = maxflow();
if(sum == res)
puts("STAY HOME");
else
printf("%d\n", sum-res);
}
}