Dynamic programming (singular State): Hnoi 2001 Product Processing

Source: Internet
Author: User

Product processing

A processing plant has a, b two machines, to process the product can be completed by any one of the machines, or two machines together to complete. Due to the limitations of machine performance and product characteristics, the time required for different machines to process the same product will be different, and the task will be different if it is processed together by two machines. One day, the processing plant received N product processing tasks, each task workload is different.

Your task is to know the time required for each task to be processed on a machine T1, the time required to process the B machine T2 and the time required to process the two machines together T3, please arrange the scheduling order of the tasks reasonably, so that the total time to complete all n tasks is the least.

Input file: (input file total n+1 line)

1th Act N. n is the total number of tasks (1≤n≤6000)

The non-negative integer t1,t2,t3 between 3 [0,5] of the I+1 Act represents the time required for the first I task to be machined on a machine, the B machine machined, and the two machines co-machined. If the given time T1 or T2 0 means that the task cannot be machined on that machine, if the T3 is 0, the task cannot be processed simultaneously by two machines.

Output file: Minimum finish time

Input Output Sample:

Input.txt output.txt

5 9

2 1 0

0 5 0

2 4 1

0 0 3

2 1 1

Found that the problem is not very good to set the state, here magically make dp[i] to represent a work I at the very small amount of work B, of course, is a scrolling array.

So the next is good to launch the results. Now I'm not enough, there's no way to do it alone.%%%

1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 Const intinf=100000000;6 Const intmaxn=50010;7 intA[MAXN],B[MAXN],C[MAXN];8 intTA[MAXN],TC[MAXN];9 intN,MX,DP[MAXN];Ten intMain () { OneFreopen ("Input.txt","R", stdin); AFreopen ("output.txt","W", stdout); -scanf"%d",&n); -      for(intI=1; i<=n;i++){ thescanf"%d%d%d",&a[i],&b[i],&c[i]); -         if(!a[i]) a[i]=INF; -         if(!b[i]) b[i]=INF; -         if(!c[i]) c[i]=INF; +     } -Memset (DP, the,sizeof(DP)); dp[0]=0; +      for(intI=1; i<=n;i++){ A         intt=0; at         if(A[i]!=inf) t=mx+A[i]; -         if(C[i]!=inf) mx+=C[i]; -mx=Max (mx,t); -          for(intj=mx;j>=0; j--){ -T=DP[J];DP [j]=INF; -             if(j-a[i]>=0) Dp[j]=min (dp[j],dp[j-A[i]]); inDp[j]=min (dp[j],t+b[i]); -             if(j-c[i]>=0) Dp[j]=min (dp[j],dp[j-c[i]]+c[i]); to         } +     } -     intans=INF; the      for(intI=0; i<=maxn-1; i++) *ans=min (Ans,max (i,dp[i)); $printf"%d\n", ans); Panax Notoginseng     return 0; -}

Dynamic programming (singular State): Hnoi 2001 Product Processing

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.