部落卫队 2281

部落卫队

Time Limit:10000MS  Memory Limit:65536K Total Submit:244 Accepted:166 Case Time Limit:1000MS

Description

原始部落byteland 中的居民们为了争夺有限的资源,经常发生冲突。几乎每个居民都有他的仇敌。部落酋长为了组织一支保卫部落的队伍,希望从部落的居民中选出最多的居民入伍,并保证队伍中任何2个人都不是仇敌。 .编程任务: 给定byteland 部落中居民间的仇敌关系,编程计算组成部落卫队的最佳方案。

Input

第1行有2个正整数n(n<=100)和m,表示byteland部落中有n位居民,居民间有m个仇敌关系。居民编号为1,2,…,n。接下来的m行中,每行有2个正整数u和v,表示居民u与居民v是仇敌。

Output

第1行是部落卫队的顶人数; 第2行是卫队组成xi ,1 ≤ i ≤ n ,xi=0 表示居民i不在卫队中,xi =1表示居民i在卫队中。

Sample Input

7    10       3    
1    2        1    0    1    0    0    0    1    
1    4    
2    4    
2    3    
2    5    
2    6    
3    5    
3    6    
4    5    
5    6   

Sample Output

3    
1    0    1    0    0    0    1    

Source


type arr=set of 0..100;
  var a,f:array[1..100]of boolean;
      s:array[1..100]of arr;
      w:arr;
      n,m,x,y,i,tot,max:longint;

procedure try(k:longint;w:arr;tot:longint);
     var i:longint;
        begin
          if (tot>max)then
            begin max:=tot; a:=f;end;

          for i:=k+1 to n do
            if not(i in w) then
              begin
                f[i]:=true;
                try(i,w+s[i],tot+1);
                f[i]:=false;
              end;
        end;

begin
  readln(n,m);
  w:=[];
  fillchar(f,sizeof(f),#0);
  max:=-maxlongint;
  for i:=1 to m do
   begin
     readln(x,y);
     s[x]:=s[x]+[y];
   end;
   try(0,w,0);
   writeln(max);
   for i:=1 to n do
     if a[i] then write('1 ')
             else write('0 ');
   writeln;
end.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值