一道简单可爱的dp
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #define max(a,b) (a>b?a:b) #define rint register int using std::sort; using std::cout; using std::endl; template <class T>inline void read(T &X) { X=0;int W=0;char ch=0; while(!isdigit(ch))W|=ch=='-',ch=getchar(); while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); X=W?-X:X;return; } int n,dp[16000000]={0},ans=0; struct node{int h,a,c;}e[410]; int cmp(node x,node y){return x.a<y.a;} int main() { read(n); for(rint i=1;i<=n;++i)read(e[i].h),read(e[i].a),read(e[i].c); sort(e+1,e+n+1,cmp); dp[0]=1; for(rint i=0;i<=n;++i) { for(rint j=e[i].a;j>=0;--j) { if(dp[j]) { for(rint k=1;k<=e[i].c;++k) { if(j+k*e[i].h>e[i].a)break; dp[j+k*e[i].h]=1; } } } } for(rint i=e[n].a;i>=0;--i) if(dp[i]){printf("%d ",i);break;} return 0; }