码迷,mamicode.com
首页 > 其他好文 > 详细

zoj 3471状态压缩DP

时间:2015-01-23 23:04:19      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:dp   状态压缩   

#include<stdio.h>
#include<string.h>
int max(int a,int b)
{
	if(a>b)
	return a;
	return b;
}
int dp[100000],map[15][15],mark[15];
int main()
{
	int i,j,n,m,k;
	while(scanf("%d",&n)!=EOF&&n)
	{
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				scanf("%d",&map[i][j]);
		memset(dp,0,sizeof(dp));
		memset(mark,0,sizeof(mark));
		int max1=0;
		m=n-1;
		for(k=0;k<(1<<(n));k++)
		{
			for(i=1;i<=n;i++)
			{
				int tot1,tot2;
				tot1=1<<(i-1);
				if(tot1&k)
				continue;
				for(j=1;j<=n;j++)
				{
					if(i==j)continue;
					tot2=1<<(j-1);
					if(tot2&k)
					continue;
					int l=k+tot2;
					dp[l]=max(dp[l],dp[k]+map[i][j]);
				}
			}
		}
		for(i=0;i<=(1<<(n));i++)
		{
			max1=max(dp[i],max1);
		}
		printf("%d\n",max1);
	}
}

zoj 3471状态压缩DP

标签:dp   状态压缩   

原文地址:http://blog.csdn.net/l133236116/article/details/43063367

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!