部落卫队pascal解题程序

type
jh=set of 0..100;//集合
var
n,m,i,u,v,tj:longint;
w:jh;
a,f:array[0..100]of boolean;
s:array[1..100]of jh;
procedure search(dep:longint;w:jh;t:longint);//dep是第几个人,w是总人数
var
i:longint;
begin
    if t>tj then
    begin
        tj:=t;
        a:=f;
    end;//a数组记录人数最多时的每个人的存在情况
    for i:=dep+1 to n do
    begin
        if not(i in w) then//w存放被选人的仇敌,第i人不是仇敌才行
        begin
            f[i]:=true;//将i选进去
            search(i,w+s[i],t+1);//搜索
            f[i]:=false;//回溯
        end;
    end;
end;
begin
    readln(n,m);//输入
    w:=[];//赋值
    fillchar(f,sizeof(f),false);//赋值
    for i:=1 to m do
    begin
        readln(u,v);
        s[u]:=s[u]+[v];
    end;
    tj:=0;//最多人数
    search(0,w,0);//搜索
    writeln(tj);
    for i:=1 to n do//输出
    if a[i]=true then write('1 ') else write('0 ');
end.
原文地址:https://www.cnblogs.com/YYC-0304/p/9500255.html