zoukankan      html  css  js  c++  java
  • POJ 2531

    直接暴力的

    #include <stdio.h>
    #include <string.h>
    #define maxn 21
    int matrix[maxn][maxn];
    int sel[maxn];
    int n;
    int max;
    int tot;
    void select(int cur)
    {
    	if(cur==n)
    	{
    		if(tot==n||tot==0) return;
    		int i,j;
    		int amount=0;
    		for(i=0;i<n;i++)
    		{
    			if(!sel[i]) continue;
    			for(j=0;j<n;j++)
    			{
    				if(sel[j]) continue;
    				amount+=matrix[i][j];
    			}
    		}
    		if(amount>max) max=amount;
    		return;
    	}
    	sel[cur]=1;//选
    	tot++;
    	select(cur+1);
    	tot--;
    	sel[cur]=0;//不选
    	select(cur+1);
    }
    int main()
    {
    	while(scanf("%d",&n)!=EOF)
    	{
    		tot=0;
    		memset(sel,0,sizeof(sel));
    		int i,j;
    		max=0;
    		for(i=0;i<n;i++)
    		{
    			for(j=0;j<n;j++)
    			{
    				scanf("%d",&matrix[i][j]);
    			}
    		}
    		sel[0]=1;
    		select(0);
    		printf("%d\n",max);
    	}
    	return 0;
    }


     

  • 相关阅读:
    Windbg DUMP
    NET媒体文件操作组件TagLib
    NET Framework、.NET Core、Xamarin
    面向切面编程
    微服务
    NET Core
    Yeoman generator
    Service Fabric
    Vue.JS 2.x
    CoreCLR
  • 原文地址:https://www.cnblogs.com/lj030/p/3002182.html
Copyright © 2011-2022 走看看