The main effect of the topic:
There are n kinds of bricks, the height of each brick is H, the quantity is C, and the highest position of it can not exceed a. How high can these bricks be stacked?
Ideas:
First of all kinds of bricks according to a from large to small sort, and then directly set multiple backpacks can be.
Code:
#include <iostream> #include <queue> #include <stack> #include <cstdio> #include <cstr ing> #include <cmath> #include <map> #include <set> #include <string> #define MP Make_pai R #define SQ (x) (x) #define MAX (x, y) ((x) > (y))?
(x):(y) typedef int int64;
Const double PI = ACOs (-1.0);
const int INF = 0X3F3F3F3F;
using namespace Std;
const int MAXN = 33;
int n, m;
struct node{int h, a, C;
BOOL operator< (const node& RHS) Const {return a < RHS.A;
}}arr[410]; inline void Zeroonepack (int* f, int V, int c, int w) {for (int i=v; i>=c;-i) f[i] = max (f[i), f[i-c]+
W); } inline void Completepack (int* f, int V, int c, int w) {for (int i=c; i<=v; ++i) f[i] = max (f[i), f[
I-C]+W); } inline void Multiplepack (int* f, int V, int c, int w, int m) {if (c*m >= V) {Completepack (f, V, C, W);
return;
int k = 1;
while (K < m) {Zeroonepack (F, V, K*c, k*w);
M-= k;
K <<= 1;
} zeroonepack (f, V, M*c, m*w);
int f[100010];
int main () {scanf ("%d", &n);
int maxx = 0;
for (int i=1; i<=n; ++i) {scanf ("%d%d%d", &arr[i].h,&arr[i].a,&arr[i].c);
Maxx = Max (Maxx, ARR[I].A);
Sort (arr+1, arr+1+n);
for (int i=0; i<=maxx; ++i) f[i] = 0;
for (int i=1; i<=n; ++i) Multiplepack (f, arr[i].a, Arr[i].h, Arr[i].h, arr[i].c);
int ans = 0;
for (int i=0; i<=maxx; ++i) ans = max (ans, f[i]);
printf ("%d\n", ans);
return 0; }
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/