[Luo gu 1113] chores

Source: Internet
Author: User

Title Description

John's farm has a lot of chores to do before milking cows, and every chore takes a certain amount of time to complete. For example: they want to bring cows together, drive them into the barn, wash their breasts and some other work for cows. It is necessary to finish all the chores as early as possible, because there is more time to squeeze more milk. Of course, some chores have to be done in the case of other chores. For example: Only the cows will be driven into the barn to start cleaning the breasts, and not to milk the cows before they wash their breasts. We refer to these as preparations for the completion of this work. At least one chore does not require preparation, and this work, which can be done as early as possible, is marked as chore 1. John has a list of n chores to complete, and the list is in a certain order, and the chore K (k>1) preparation is only possible in chore 1. The k-1.
Write a program from 1 to n read the job description of each chore. Calculates the shortest time that all chores are completed. Of course, chores that are not related to each other can work at the same time, and you can assume that John's farm has enough workers to do any number of tasks at the same time.

input/output format

Input format:

Line 1th: An integer n, the number of chores that must be completed (3<=n<=10,000);
2nd ~ n+1: A total of n rows, each line has a number of 1 spaces separated by an integer, respectively, said:
* Work Sequence Number (1..N, in the input file is ordered);
* The time required to complete the work Len (1<=len<=100);
* Some must-do preparations, the total number of not more than 100, by a number of 0 end. Some chores do not need to be prepared for a job that only describes a single 0, no extra spaces appear in the entire input file.

Output format:

An integer that represents the minimum time required to complete all chores.

input/Output sample

Input Sample # #:

71 5 02 2 1 03 3 2 04 6 1 05 1 2 4 06 8 2 4 07 4 3 5 6 0

Sample # # of output:

23
Ideas

The cost of doing the work of the current node equals the sum of the preceding cost and the current node cost.

varA:Array[1..10000] ofLongint;  I,j,k,l,m,n:longint; beginREADLN (n); Fillchar (A,sizeof (a),0); M:=0;  fori:=1  toN Do          beginread (K,L,J); K:=0;  whileJ<>0  Do                  begin                      ifA[j]>k Thenk:=A[j];                  Read (j); End; A[i]:=k+l; ifA[i]>m Thenm:=A[i]; End;  Write (m); End.
View Code

This could be more straightforward.

 ProgramAA; varT:Array[1..10000] ofLongint;  N,i,a,b,max,ans:longint; beginREADLN (n);  fori:=1  toN Do      beginread (a);          Read (T[a]); Max:=0;  while 1>0  Do          beginread (b); ifb=0  ThenBreak ; ifT[b]>max Thenmax:=T[b]; End; T[a]:=t[a]+Max; End;  fori:=1  toN Do          ifT[i]>ans Thenans:=T[i];    Writeln (ANS); End.
View Code

I hear I can do it the longest way (Caitlin)

 Programexam1; varMapArray[1..1000000,1..3] ofLongint; varF:Array[1..10000] ofLongint; varV:Array[1..10000] ofBoolean; varH:Array[1..1000000] ofLongint; varFirstArray[1..10000] ofLongint; varBb:Array[1..10000] ofLongint; varTot,i,j,n,x,y,z,l,r,q,tt,qi,zhong,ans,len,num:longint; procedureInsert (A,b,c:longint); beginInc (TOT); Map[tot,1]:=b; Map[tot,2]:=C; Map[tot,3]:=First[a]; First[a]:=tot; End; procedureSPFA (Ss:longint); begin// fori:=1  toN Do//ifI<>ss Thenf[i]:=100000000; Fillchar (H,sizeof (h),0); L:=0; R:=1; h[1]:=SS; V[SS]:=true;  whileL<r Do  beginInc (L); Q:=H[l]; TT:=First[q];  whileTt<>0  Do  begin  ifF[map[tt,1]]<f[q]+map[tt,2] Then  beginF[map[tt,1]]:=f[q]+map[tt,2]; ifF[map[tt,1]]>ans Thenans:=f[map[tt,1]]; if  notV[map[tt,1]] Then  beginInc (R); H[R]:=map[tt,1]; V[map[tt,1]]:=true; End; End; TT:=map[tt,3]; End; V[Q]:=false; End; End; proceduresearch; varIi:longint; begin   forii:=1  toN Do  ifF[ii]>ans Thenans:=F[ii]; End; beginread (n);  fori:=1  toN Do  beginread (Zhong);  Read (len);  Read (QI); ifQi=0  Then  beginInc. (NUM); Bb[num]:=Zhong; F[zhong]:=Len; End  Else   whileQi<>0  Do  beginInsert (Qi,zhong,len);  Read (QI); End; End; // fori:=1  toN Do//iff[i]=0  Thenf[i]:=100000000;  fori:=1  toNum DoSPFA (Bb[i]); //search;  Writeln (ANS); End.
View Code

Another model made of diagrams (roadside ditches)

varN:longint; F:Array[0..10000] ofLongint;    I,s,h,t,max:longint;  Ans:longint; beginREADLN (n);  fori:=1  toN Do      beginread (s);//read in.      S is the current processing item number, and T is time consuming for the current processing.      Read (t);      Read (h); Max:=0;  whileH>0  Do        begin        ifF[h]>max ThenMAX:=F[H]; //find the most time-consuming item from the task that the current processing item must complete.        At this point, the project can be done simultaneously at the same time, the resulting sum is the smallest.        Read (h); End;      READLN; F[s]:=max+t; //plus the time-consuming of the current processifF[s]>ans Thenans:=F[s]; End;  Writeln (ANS); End.
View Code

[Luo gu 1113] chores

Related Keywords:

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.