Soj 3664 chess towers [Full bag deformation]

Source: Internet
Author: User

Soj 3664 chess towers

This is a question for the training team last night.

The question of usaco cows.

In a two-hour competition, question a is a big question, because the meaning of the question is wrong,

A waste of nearly an hour. Read questions.

So that I am not in the mood to write this question. After returning to the dormitory, decisive a drop.

Given some different chess, each height is known, the value is known, and the number is infinite.

Find the maximum value that t can achieve when stacked together.

(Without the following conditions, this part is a bare full backpack)

Note that if a chess with a height greater than or equal to k appears, all the following chess Heights will be compressed

The original 4/5 .. Note that each chess can only be compressed once.

 

The procedure is also simple:

Perform a full backpack once and obtain 1 to 2 * t (note that the size is slightly larger here, and the compression below may be within T ).

The greatest value in height. Here we can find the largest value of 1 to T ans

Then enumerate (if any) those chess whose height is> = K and put them on the top,

It will get a compressed height and the new value of this height. And update the answer ans.

 

# Include <iostream> <br/> # include <algorithm> <br/> # include <cstring> <br/> # include <cstdio> <br/> # include <queue> <br/> # include <vector> <br/> using namespace STD; <br/> const int max = 11000; <br/> const int INF = 0x1fffffff; </P> <p> int N, T, K, DP [Max]; <br/> struct node <br/> {<br/> int V, H; <br/>} nod [Max]; <br/> bool CMP (node, node B) <br/>{< br/> return. h <B. h; <br/>}< br/> void Init () <br/>{< br/> int I; <br/> DP [0] = 0; <br/> for (I = 1; I <= 2 * t; I ++) DP [I] =-1; <br/>}< br/> int main () <br/>{< br/> int I, j, Hei, Val, K; <br/> while (scanf ("% d", & N, & T, & K) = 3) <br/> {<br/> for (I = 1; I <= N; I ++) scanf ("% d", & nod [I]. v, & nod [I]. h); <br/> sort (& nod [1], & nod [n + 1], CMP); </P> <p> Init (); </P> <p> K =-1; <br/> for (I = 1; I <= N; I ++) <br/> {<br/> If (nod [I]. h >=k) {k = I; break ;}< br/> Hei = nod [I]. h; <br/> val = nod [I]. v; <br/> for (j = 0; j <= 2 * t; j ++) <br/>{< br/> If (DP [J] =-1) continue; <br/> DP [J + Hei] = max (DP [J + Hei], DP [J] + val ); <br/>}< br/> K = I; <br/> int ans = 0; <br/> for (I = 1; I <= T; I ++) ans = max (ANS, DP [I]); <br/> If (k =-1) {printf ("% d/N", ANS); Continue ;}</P> <p> for (I = K; I <= N; I ++) <br/> {<br/> Hei = nod [I]. h; <br/> val = nod [I]. v; <br/> for (j = 0; j <= 2 * t; j ++) <br/>{< br/> If (DP [J] =-1) continue; <br/> DP [J + Hei] = max (DP [J + Hei], DP [J] + val ); <br/>}</P> <p> for (I = K; I <= N; I ++) <br/> {<br/> for (j = 0; j <= 2 * t; j ++) <br/> {<br/> If (DP [J] =-1) continue; <br/> int HH = nod [I]. H + J * 4/5; <br/> If (HH> T) break; <br/> ans = max (ANS, DP [J] + nod [I]. v); <br/>}< br/> printf ("% d/N", ANS ); <br/>}< br/> // system ("pause"); <br/> return 0; <br/>}</P> <p>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.