Hdu 4462 Scaring the Birds(枚举子集)

58 篇文章 0 订阅
11 篇文章 0 订阅

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4462

思路:有坑。可放置稻草人的地方无需覆盖;当k==n*n时,答案为0。

#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=55;
const int INF=0x3f3f3f3f;
struct Node
{
    int x,y;
};
int R[15];
Node p[15];
int ans,n,k;
vector<int> pick;
int v[maxn][maxn];
void Find()
{
    for(int a=1; a<=n; a++)
    {
        for(int b=1; b<=n; b++)
        {
            if(v[a][b]) continue;
            int flag=0;
            for(int i=0; i<pick.size(); i++)
            {
                int P=pick[i];
                if(abs(a-p[P].x)+abs(b-p[P].y)<=R[P])
                {
                    flag=1;
                    break;
                }
            }
            if(!flag) return ;
        }
    }
    int tmp=pick.size();
    ans=min(ans,tmp);
}
int main()
{
    while(scanf("%d",&n)==1&&n)
    {
        ans=INF;
        scanf("%d",&k);
        memset(v,0,sizeof(v));
        for(int i=0; i<k; i++)
        {
            scanf("%d%d",&p[i].x,&p[i].y);
            v[p[i].x][p[i].y]=1;
        }
        for(int i=0; i<k; i++)
            scanf("%d",&R[i]);
          if(k==n*n)
        {
            printf("0\n");
            continue;
        }
        for(int S=0; S<(1<<k); S++)
        {
            pick.clear();
            for(int i=0; i<k; i++)
                if(S&(1<<i)) pick.push_back(i);
            if(pick.size()<ans) Find();
        }
        if(ans==INF) printf("-1\n");
        else printf("%d\n",ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值