NOIP2016 2831 Angry Birds __ Dynamic Planning

Source: Internet
Author: User

Topic description

Kiana recently addicted to a magical game can not extricate themselves.

In short, the game is done on a flat surface.

There is a slingshot located at (0,0), each kiana can use it to launch a red bird to the first quadrant, the birds flight trajectory are shaped like y=ax^2+bx curve, where A,b is the Kiana specified parameters, and must meet the a<0.

When the bird falls back to the ground (that is, the x axis), it disappears instantly.

At a certain level in the game, the first quadrant of the plane has n green pigs, of which the coordinates of the little Pig are (xi,yi).

If a bird's flight trajectory passes (xi,yi), then the first pig will be destroyed, and the bird will continue to fly along the original trajectory;

If a bird's flight trajectory does not pass (Xi,yi), then the whole process of the bird's flight will not have any effect on the first pig.

For example, if two piglets were located in (1,3) and (3,3), Kiana could choose to launch a bird with a flight trajectory of y=-x^2+4x, so that two piglets would be wiped out by the bird.

And the purpose of this game is to kill all the piglets by launching the birds.

Every level of this magical game is difficult for Kiana, so Kiana also entered some mysterious instructions to make it easier for him to complete the game. These directives are detailed in the input format.

Assuming that the game has a total of T hurdles, now Kiana want to know, for each checkpoint, at least how many birds need to launch to destroy all the piglets. Since she doesn't count, she wants you to tell her.
Input output Format input format:

The first line contains a positive integer t that represents the total number of levels in the game.

Below, enter the information of the T checkpoint. The first line of each checkpoint contains two non-negative integer n,m, representing the number of piglets in the checkpoint and the type of mysterious instruction Kiana entered. In the next n rows, line I contains two positive real numbers (Xi,yi), indicating that the first pig coordinates are (xi,yi). The data guarantee that there are no two pigs with identical coordinates in the same checkpoint.

If m=0, the Kiana enters a directive that has no effect.

If m=1, then this checkpoint will be satisfied: at most with a small bird can eliminate all piglets.

If m=2, then this checkpoint will be satisfied: there must be an optimal solution, one of the birds destroyed at least a little pig.

Guaranteed 1<=n<=18,0< =m<=2,0< xi,yi<10, the real numbers in the input are kept to two digits after the decimal point.

Above, the symbol and the separate representation of the C up and down rounding

Output format:

Output one line of answers in turn for each hurdle.

Each row of the output contains a positive integer that represents the corresponding level, eliminating the minimum number of birds needed by all piglets

DP, the pretreatment of a two pig can eliminate which pigs, and then for each state, find the first not eliminated pig, enumerate it and which pairing, complexity O (2^n * n).

#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std;
Double eps=1e-10;
int dp[270000],n,f[20][20];
Double x[20],y[20];
    void init () {int i,j,k;
    Double a,b;
    scanf ("%d%*d", &n);
    for (i=0;i<n;i++) scanf ("%lf%lf", &x[i],&y[i));
    memset (F,0,sizeof (f));
        for (i=0;i<n;i++) for (j=i+1;j<n;j++) {a= (Y[J]*X[I]-Y[I]*X[J))/((x[j]-x[i)) *x[j]*x[i]);
        B= (Y[j]*x[i]*x[i]-y[i]*x[j]*x[j])/((X[i]-x[j]) *x[i]*x[j]);
        if (a>=-eps) continue;
      for (k=i;k<n;k++) if (Fabs (a*x[k]*x[k]+b*x[k]-y[k)) <=eps) f[i][j]|=1<<k;
    an int solve () {int s,i,j;
    Memset (Dp,0x3f,sizeof (DP));
    dp[0]=0;
        For (s=0;s< (1<<n) -1;s++) {i=0;
        while (s& (1<<i)) i++; dp[s| ( 1<<i)]=min (dp[s|) (
        1<<i)],dp[s]+1); for (j=i;j<n;j++) dp[s|f[i][j]]=min (DP[S|F[I][J]],DP[s]+1);
Return dp[(1<<n)-1];
    int main () {int T;
    scanf ("%d", &t);
        while (t--) {init ();
    printf ("%d\n", Solve ()); }
}

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.