Hdu 4462 Scaring the Birds (enumeration subset)

Source: Internet
Author: User

Title Address: http://acm.hdu.edu.cn/showproblem.php?pid=4462

Idea: There is a pit. Where the scarecrow can be placed without covering; When k==n*n, the answer is 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;}


Hdu 4462 Scaring the Birds (enumeration subset)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.