1 条题解

  • 0
    @ 2024-6-14 22:17:52

    用二进制分组就可以了:

    #define int long long
    #define elif else if
    #define fin(x) freopen (x, "r", stdin)
    #define fout(x) freopen (x, "w", stdout)
    #define reg(i,x,y) for (register int i = (x); i <= (y); ++i)
    #define Reg(i,x,y) for (register int i = (y); i >= (x); --i)
    using namespace std;
    int n,w;
    struct bw{
    	int x,y,z;
    };
    vector<bw> a,b;
    vector<int> f;
    inline int read (void) {int x = 0,f = 0;char ch = getchar ();while (!isdigit (ch)) {f |= (ch == '-');ch = getchar ();}while (isdigit (ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar ();return f ? -x : x;}
    inline string rstr (void) {string s = "";char ch = getchar ();while (ch != '\n' && ch != EOF) {if (ch != ' ') s += ch;ch = getchar ();}return s;}
    inline char rch (void) {char ch = getchar ();while (ch == ' ' || ch == '\n') ch = getchar ();return ch;}
    inline void write (int x = 0) {if (x < 0) putchar ('-'),x = -x;if (x > 9) write (x / 10);putchar (x % 10 | 48);}
    inline void write_ (int x = 0,char ch = ' ') {write (x);putchar (ch);}
    signed main ()
    {
    	n = read (),w = read ();
    	a.resize (n + 1);
    	b.resize (1);
    	f.resize (w + 1);
    	reg (i,1,n) a[i].x = read (),a[i].y = read (),a[i].z = read ();
    	reg (i,1,n)
    		reg (j,0,63)
    		{
    			if (a[i].z < (1 << j) && a[i].z != 0) {b.push_back ({a[i].x * a[i].z,a[i].y * a[i].z,0});break;}
    			if (!a[i].z) break;
    			int s = (1 << j);
    			b.push_back ({a[i].x * s,a[i].y * s,0});
    			a[i].z -= s;
    		}
    	reg (i,1,b.size () - 1)
    		Reg (j,b[i].y,w)
    			f[j] = max (f[j],f[j - b[i].y] + b[i].x);
    	write (f[w]);
    	return 0;
    }
    
    
    • 1

    信息

    ID
    333
    时间
    1000ms
    内存
    256MiB
    难度
    2
    标签
    (无)
    递交数
    40
    已通过
    26
    上传者