求助wwwwww
查看原帖
求助wwwwww
1121929
2023nsty04楼主2024/4/19 23:03
#include<bits/stdc++.h>
using namespace std;
int n,m,x[100],maxn=0,ans[100];
bool book[100][100]={0};
bool check(int p)
{
    for(int i=1;i<p;i++)
    {
        if(x[i]==1&&book[p][i]==1)return 0;
    }
    return 1;
}
void dfs(int num/*卫队人数*/,int step/*当前*/)
{
    if(step>n)
    {
        if(num>maxn)
        {
            maxn=num;
            for(int i=1;i<=n;i++)ans[i]=x[i];
        }
        return;
    }
    if(check(step))
    {
        x[step]=1;
        dfs(num+1,step+1);
        x[step]=0;
    }
    dfs(num,step+1);    
}
int main()
{
    cin>>n>>m;
    int u,v;
    for(int i=1;i<=m;i++)
    {
        cin>>u>>v;
        book[u][v]=1,book[v][u]=1;
    }
    dfs(0,1);
    cout<<maxn<<endl;
    for(int i=1;i<=n;i++)printf("%d ",ans[i]);
    return 0;
}

大佬们能不能帮我看看为什么在最后一个测试点会wrong answer,谢谢!

2024/4/19 23:03
加载中...