Hdoj 3535 areyoubusy (each group contains at least one backpack)

Source: Internet
Author: User

Link: (-_-) ZZ

There are N types of work sets. Each type of set has one type. 0 is to select at least one job in the Set, and 1 is to select one job in the set at most, 2. It takes a certain amount of time and happiness to make every job.

Idea: If the type is 0, it is the deformation of the group backpack. If it is 1, it is the group backpack. If it is 2, it is the 0-1 backpack. You can find it based on the type of the backpack.

PS: unlimited wa

Code:

# Include <stdio. h> # include <string. h> struct node {int T, H;} pack [5] [100002]; int C = 0, n = 0, T = 0, DP [102] [102], num [5] [102], index1 [5], IND [102]; void zeropack (INT in, int start) // select at least one {int I = 0, j = 0, K = 0, tpval = 0; for (I = 0; I <num [0] [in]; I ++) {for (j = T; j> = pack [0] [start + I]. t; j --) {If (DP [C] [J-pack [0] [start + I]. t]! =-1) DP [C] [J] = DP [C] [J]> DP [C] [J-pack [0] [start + I]. t] + pack [0] [start + I]. h? DP [C] [J]: DP [C] [J-pack [0] [start + I]. t] + pack [0] [start + I]. h; If (DP [C-1] [J-pack [0] [start + I]. t]! =-1) DP [C] [J] = DP [C] [J]> DP [C-1] [J-pack [0] [start + I]. t] + pack [0] [start + I]. h? DP [C] [J]: DP [C-1] [J-pack [0] [start + I]. t] + pack [0] [start + I]. h ;}} void onepack (INT in, int start) // You can select at most one grouping backpack. {int I = 0, j = 0, K = 0, tpval = 0; for (I = 0; I <= T; I ++) DP [C] [I] = DP [C-1] [I]; for (I = T; i> = 0; I --) {for (j = 0; j <num [1] [in]; j ++) if (pack [1] [start + J]. T <= I & DP [C-1] [I-pack [1] [start + J]. t]! =-1) DP [C] [I] = DP [C] [I]> DP [C-1] [I-pack [1] [start + J]. t] + pack [1] [start + J]. h? DP [C] [I]: DP [C-1] [I-pack [1] [start + J]. t] + pack [1] [start + J]. h ;}} void twopack (INT in, int start) // 0-1 backpack {int I = 0, j = 0, K = 0, tpval = 0; for (I = 0; I <= T; I ++) DP [C] [I] = DP [C-1] [I]; for (I = 0; I <num [2] [in]; I ++) {for (j = T; j> = pack [2] [start + I]. t; j --) {If (DP [C] [J-pack [2] [start + I]. t]! =-1) DP [C] [J] = DP [C] [J]> DP [C] [J-pack [2] [start + I]. t] + pack [2] [start + I]. h? DP [C] [J]: DP [C] [J-pack [2] [start + I]. t] + pack [2] [start + I]. h ;}} C ++ ;}int main () {int I = 0, j = 0, m = 0, S = 0, start = 0, ANS =-1; while (scanf ("% d", & N, & T )! = EOF) {c = 1; memset (index1, 0, sizeof (index1); memset (IND, 0, sizeof (IND); memset (DP,-1, sizeof (DP); for (I = 0; I <= T; I ++) DP [0] [I] = 0; for (I = 0; I <n; I ++) {scanf ("% d", & M, & S); num [s] [index1 [s] ++] = m; // index1 [s] indicates the number of classes in S for (j = 0; j <m; j ++, IND [s] ++) {scanf ("% d", & Pack [s] [ind [s]. t); scanf ("% d", & Pack [s] [ind [s]. h) ;}} start = 0; For (j = 0; j <index1 [0]; j ++) // The total number of groups of classes belonging to 0 {zeropack (J, start); start + = num [0] [J]; C ++;} start = 0; for (j = 0; j <index1 [1]; j ++) {onepack (J, start); start + = num [1] [J]; c ++;} start = 0; For (j = 0; j <index1 [2]; j ++) {twopack (J, start ); start + = num [2] [J];} printf ("% d \ n", DP [C-1] [T]);} return 0 ;}

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.