bzoj4247: Hanging Ornaments

Source: Internet
Author: User
Tags min

The

Sorts the number of hooks from large to small, and then f[i] [j] represents the maximum value of the remaining J hooks for the first I decoration, and the transfer is very simple

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace
Std
    int read () {char ch=getchar (); int f=0,x=1; while (ch< ' 0 ' | |
    Ch> ' 9 ') {if (ch== '-') X=-1;ch=getchar ();}
    while (ch>= ' 0 ' &&ch<= ' 9 ') {f= (f<<1) + (f<<3) +ch-' 0 '; Ch=getchar ();}
return f*x;
} int f[2005][4005],n,a[2005],b[2005];
    struct data {int A;
int b;
}Q[2005]; 
    BOOL CMP (const data &AMP;A,CONST data &b) {return a.a>b.a;} int main () {memset (f,-0x7f7f7f7f,sizeof (f));
    N=read ();
    for (int i=0;i<=n;i++) {for (int j=0;j<=2*n;j++) f[i][j]=-2100000000;
    }f[0][1]=0;
    for (int i=1;i<=n;i++) {q[i].a=read (); Q[i].b=read ();
    }sort (Q+1,Q+N+1,CMP);
                for (int i=1;i<=n;i++) {for (int j=0;j<=2*n;j++) {if (j) {
                F[i][min (j+q[i].a-1,2*n)]=max (F[i-1][j]+q[i].b,f[i][min (j+q[i].a-1,2*n)]); F[I][J]=max (F[i][j],f[i-1][j]);
            } else {F[i][j]=max (f[i][j],f[i-1][j]);
    }}} int ans=0;
    for (int i=0;i<=2*n;i++) Ans=max (Ans,f[n][i]);
cout<<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.