hdu3535---areyoubusy (mixed group backpack with pit point)

Source: Internet
Author: User

Mixed Pack backpack, if any, it's a 01 backpack.
If you take at most one, it's a normal pack.
If at least one, consider the first and non-first take, note that because the volume can be 0, so first to consider the first take, or a group of the same item will be calculated 2 times

/************************************************************************* > File Name:hdu3535.cpp > Auth Or:alex > Mail: [email protected] > Created time:2015 May 10 Sunday 16:06 19 seconds ******************************** ****************************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace STD;Const DoublePI =ACOs(-1.0);Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-15;typedef Long LongLL;typedefPair <int,int> PLL;intdp[ the][ the];inttype[ the]; vector <PLL>jobs[ the];intMain () {intN, T, M, C, G; while(~scanf("%d%d", &n, &t)) {memset(DP,-1,sizeof(DP)); for(inti =1; I <= N; ++i) {jobs[i].clear ();scanf("%d%d", &m, &type[i]); for(intj =1; J <= M; ++J) {scanf("%d%d", &c, &g);            Jobs[i].push_back (Make_pair (c, G)); }        } for(inti =0; I <= t; ++i) {dp[0][i] =0; } for(inti =1; I <= N; ++i) {intSize = Jobs[i].size ();if(Type[i] = =0) { for(intj =0; J < size; ++J) { for(intK = t; K >= Jobs[i][j].first; --K) {if(Dp[i][k-jobs[i][j].first]! =-1{Dp[i][k] = max (Dp[i][k], Dp[i][k-jobs[i][j].first] + jobs[i][j].second); }if(Dp[i-1][k-jobs[i][j].first]! =-1) {Dp[i][k] = max (Dp[i][k], dp[i-1][k-jobs[i][j].first] + jobs[i][j].second); }                    }                }            }Else if(Type[i] = =1) { for(intj =0; J <= T; ++J) {Dp[i][j] = dp[i-1][J]; } for(intj =0; J <= T; ++J) { for(intK =0; K < size; ++K) {if(J < Jobs[i][k].first) {Continue; }if(Dp[i-1][j-jobs[i][k].first]! =-1) {Dp[i][j] = max (Dp[i][j], dp[i-1][j-jobs[i][k].first] + jobs[i][k].second); }                    }                }            }Else{ for(intj =0; J <= T; ++J) {Dp[i][j] = dp[i-1][J]; } for(intj =0; J < size; ++J) { for(intK = t; K >=0; --K) {if(K < Jobs[i][j].first) { Break; }if(Dp[i][k-jobs[i][j].first]! =-1{Dp[i][k] = max (Dp[i][k], Dp[i][k-jobs[i][j].first] + jobs[i][j].second); }                    }                }            }        }printf("%d\n", Dp[n][t]); }return 0;}

hdu3535---areyoubusy (mixed group backpack with pit point)

Related Article

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.