bzoj 4247挂饰

背包????不会。。。

 1 #include<bits/stdc++.h>
 2 #define INF 0x7fffffff
 3 #define LL long long
 4 #define N 100005
 5 using namespace std;
 6 inline int ra()
 7 {
 8     int x=0,f=1; char ch=getchar();
 9     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
10     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
11     return x*f;
12 }
13 struct node{int a,b;}a[N];
14 LL f[2005][2005];
15 bool cmp(node a, node b){return a.a>b.a;}
16 int main()
17 {
18     int n=ra();
19     for (int i=1; i<=n; i++) a[i].a=ra(),a[i].b=ra();
20     sort(a+1,a+n+1,cmp);
21     for (int i=0; i<=n; i++) for (int j=0; j<=n+1; j++) f[i][j]=-0x3f3f3f3f; f[0][1]=0;
22     for (int i=1; i<=n; i++)
23         for (int j=0; j<=n; j++)
24             f[i][j]=max(f[i-1][j],f[i-1][max(j-a[i].a,0)+1]+a[i].b);
25     LL ans=-0x3f3f3f3f;
26     for (int i=0; i<=n; i++)
27         ans=max(ans,f[n][i]);
28     cout<<ans;
29     return 0;
30 } 

 

posted @ 2017-02-07 17:23  ws_ccd  阅读(93)  评论(0编辑  收藏  举报