标签:
3
7 40 3
5 23 8
2 52 6
48
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<vector> using namespace std; int n,k,hc,h[1005],c[1005],a[1005],ans; bool f[40205]; struct ITM{ int h; int c; int a; }temp; bool cmp(ITM x,ITM y){ return x.a < y.a; } vector<ITM> itm; int main(){ cin>>n; for(int i = 1;i <= n;i++){ scanf("%d%d%d",&h[i],&a[i],&c[i]); k = 1; while(c[i] >= k){ temp.a = a[i]; temp.c = k; temp.h = h[i]; c[i] -= k; k <<= 1; itm.push_back(temp); } if(c[i]){ temp.a = a[i]; temp.c = c[i]; temp.h = h[i]; itm.push_back(temp); } } sort(itm.begin(),itm.end(),cmp); n = itm.size(); f[0] = true; for(int i = 0;i < n;i++){ hc = itm[i].h*itm[i].c; for(int j = itm[i].a;j >= itm[i].h;j--){ if(f[j-hc]) f[j] = true; if(f[j]) ans = max(ans,j); } } cout<<ans; return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5791376.html