ZOJ3554 A miser Boss (DP)

Source: Internet
Author: User
Tags bitset time 0

Reprint Please specify source: http://www.cnblogs.com/fraud/--by fraud

A Miser Boss Time limit: 2 Seconds Memory Limit: 65536 KB

There is three different lathes in a factory namely A,b,c. They is all able to work on all kinds of workpieces. And there is N workpieces to being processed, denoted by ,.., n.

Due to different internal implemetations, for a specific workpiece I, it costs a a[i] seconds to finish The job on it while B takes B[i] and C takes C[i] seconds. Each lathe can work on at the most one workpiece a time.

Additionally, the Boss is so stingy that he didn ' t want his lathes to being disengaged at any time before the end of the work . That is:
1. There should not being a time when one of the lathes are in leisure.
2. All lathes should stop Simultaneously,and start from time 0.

Your task is to find if there exists a arrangement meeting with the constraints above. If there is,output the minimal time needed to process all the workpieces. Output a line NO else.

Input

There is multiple test cases. The first line of all case are an integer N (0 < n≤40) , followed by N lines. In the following N lines, line i contains three integer,A[i],b[i],c[i] (0 < a[i],b[i],c[i]≤120 && 0 < sum (a[i]), SUM (b[i]), SUM (C[i]) ≤120) indicating the seconds a,b,c takes to process workpiece I .

Output

Output one line the minimal seconds it takes to process all workpieces within the constraints if there are an arrangement. Print NO if not.

Sample Input
37 1 21 7 11 3 721 2 33 2 1
Sample Output
1NO

Forgive me stupid, can only think of n*120*120*120 method, Dp[i][j][k][l] said to take the first I when a take the sum is J,b is K,c is L this scheme is feasible

As long as the judgment is feasible, then in fact, the four-dimensional can be optimized. So I think I can use bitset, every time just or a little, yes, it's so simple and rude.

1 /**2 * Code generated by Jhelper3 * More info:Https://github.com/AlexeyDmitriev/JHelper4 * @author Xyiyy @Https://github.com/xyiyy5  */6 7#include <iostream>8#include <fstream>9 Ten //##################### One //Author:fraud A //Blog:http://www.cnblogs.com/fraud/ - //##################### - //#pragma COMMENT (linker, "/stack:102400000,102400000") the#include <iostream> -#include <sstream> -#include <ios> -#include <iomanip> +#include <functional> -#include <algorithm> +#include <vector> A#include <string> at#include <list> -#include <queue> -#include <deque> -#include <stack> -#include <Set> -#include <map> in#include <cstdio> -#include <cstdlib> to#include <cmath> +#include <cstring> -#include <climits> the#include <cctype> *  $ using namespacestd;Panax Notoginseng #defineRep (X, N) for (int x=0; x<n; X + +) - #defineREP2 (X, L, R) for (int x=l; x<=r; X + +) the  + inta[ the], b[ the], c[ the]; A  the#include <bitset> +  -bitset<121> dp[ the][121][121]; $  $ classTASKF { -  Public: -     voidSolve (Std::istream &inch, Std::ostream & out) { the         intN; -          while(inch>>N) {Wuyi             inttot =0; theREP2 (I,1, N) { -                 inch>> A[i] >> B[i] >>C[i]; WuTot + =C[i]; -             } AboutRep (i, n +1) $Rep (J,121) -Rep (K,121) Dp[i][j][k].reset (); -             intTA =0, TB =0; -dp[0][0][0][0] =1; AREP2 (I,1, N) { +Rep2 (J,0, TA) { theRep2 (k,0, TB) { -Dp[i][j + a[i]][k] |= dp[i-1][j][k]; $Dp[i][j][k + b[i]] |= dp[i-1][j][k]; theDp[i][j][k] |= (Dp[i-1][J][K] <<c[i]); the                     } the                 } theTa + =A[i]; -TB + =B[i]; in             } the             intAns =0; theREP2 (I,1, -) { About                 if(Dp[n][i][i][i]) { theAns =i; the                      Break; the                 } +             } -             if(ANS) out<< ans <<Endl; the             Else  out<<"NO"<<Endl;Bayi         } the     } the }; -  - intMain () { theStd::ios::sync_with_stdio (false); theStd::cin.tie (0); the TASKF solver; theStd::istream &inch(std::cin); -Std::ostream & out(std::cout); theSolver.solve (inch, out); the     return 0; the}

ZOJ3554 A miser Boss (DP)

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.