bzoj4247: 挂饰
背包。
我本来想的是一维挂饰一维钩子,但是发现空间好像会炸,但其实钩子那维开到n就可以了,再多也没用
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> using namespace std; struct node { int a,b; }c[2100]; bool cmp(node n1,node n2){return n1.a>n2.a;} int f[2100][2100]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d%d",&c[i].a,&c[i].b); sort(c+1,c+n+1,cmp); memset(f,-63,sizeof(f));f[0][1]=0; for(int i=1;i<=n;i++) for(int j=0;j<=n;j++) f[i][j]=max(f[i-1][j],f[i-1][max(j-c[i].a,0)+1]+c[i].b); int ans=0; for(int i=0;i<=n;i++)ans=max(ans,f[n][i]); printf("%d",ans); return 0; }
pain and happy in the cruel world.