Jzoj 5276 Magical Toys

Source: Internet
Author: User
Tags min
Description


Analysis

Is not a look like what network streamline planning and so on.
However, there is no train of thought, a violent, plus pruning but run fast
Plot, toy for edge, shop for Point
Search for the selected points, then one side of the two points of the link must have an election
Plus some feasibility, optimal pruning
The complexity is said to be O (Fibonacci (40)). Code

by Alan_cty (ORZ)

#include <cstdio> #include <cstring> #include <algorithm> #define FO (i,a,b) for (int i=a;i<=b;i++) #
Define REP (i,a) for (int i=last[a];i;i=next[i]) using namespace std;
const int m=45,n=105;
int n,m,k,a,b,c,d,l,sum,ans,tot,val[m],bz[m];
int last[m],next[n*2],t[n*2],v[n*2]; void Add (int x,int y,int z) {t[++l]=y;v[l]=z;next[l]=last[x];last[x]=l;} void dfs (int x,int y,int z) {if (y>
    k) return;
    if (y+m-x+1<k) return;
    if (Z>=ans) return;
        if (x>m) {ans=z;
    Return
    } if (Bz[x]) DFS (X+1,Y,Z);
            else {rep (i,x) {if (!bz[t[i]]) y++;
            bz[t[i]]++;
        Z+=v[i];
        } bz[x]=0;
        DFS (x+1,y,z+val[x]);
            Rep (i,x) {if (bz[t[i]]==1) y--;
            bz[t[i]]--;
        Z-=v[i];
        } bz[x]=1;
        DFS (X+1,Y+1,Z);
    bz[x]=0;
    }} int main () {freopen ("toy.in", "R", stdin);
    Freopen ("Toy.out", "w", stdout); scanf ("%d%d%d ", &n,&m,&k);
        Fo (i,1,n) {scanf ("%d%d%d%d", &a,&b,&c,&d);
            if (a==c) {sum+=min (b,d);
            if (!bz[a]) tot++;
            bz[a]++;
        Continue
        } if (a>c) swap (a,c), swap (B,D);
        Add (A,c,max (d-b,0));
        Val[c]+=max (b-d,0);
    Sum+=min (B,D);
    } ans=0x7fffffff;
    DFS (1,tot,0);
printf ("%d\n", Sum+ans); }

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.