Question Bank Questions 2011-12-29

Source: Internet
Author: User

Algorithm implementation problem 8-7 question Bank questions (exercise 8-18)
´ Problem Description:
Suppose there is an n-question in a question bank. Each question is marked with the category. There may be multiple categories of the same topic
Property. Now from the question bank to extract the M-track composition test paper. The test paper is required to contain the specified type of question. Try to design a
The group volume algorithm that satisfies the requirement.
´ Programming tasks:
For a given set of volume requirements, calculate the group volume scheme that meets the requirements.
´ Data input:
The input data is provided by the file Input.txt. The 1th line of the file has 2 positive integers n and K (2 <=k<=, k<=n<= 1000)
K indicates the total number of questions in the question bank and N indicates the total number of questions in the question bank. The 2nd line has k positive integers, and I positive integers
Represents the number of type I to select. The sum of the K numbers is the total number of questions m to be selected. The next n lines give the question
The type information for each question in the library. The 1th positive integer p of each line indicates that the problem can belong to the P class, and then the number of P is
The type number to which the problem belongs.
´ result output:
Output the group volume scheme to file Output.txt at the end of the program run. Line I output "I:" followed by class
The problem number of type I. If there are multiple scenarios that meet the requirements, just output 1 scenarios. If the problem is not solved, the output "no
Solution! ".
Example output file for input file sample
Input.txt

3 15
3 3 4
2 1 2
1 3
1 3
1 3
1 3
3 1 2 3
2 2 3
2 1 3
1 2
1 2
2 1 2
2 1 3
2 1 2
1 1
3 1 2 3

Output.txt

1:1 6 8
2:7 9 10
3:2 3 4 5

——————————————

1 Program Stone;2 varI,n,m,flow,tot,s,t,le:longint;3Head,vh,dis,cur:Array[0.. -] ofLongint;4Next,date,point:Array[-20000..20000] ofLongint;5  procedureAdd (x,y,z:longint);6   begin7 Inc (LE);8date[le]:=Z;9point[le]:=y;Tennext[le]:=Head[x]; Onehead[x]:=le; Apoint[-le]:=x; -next[-le]:=Head[y]; -head[y]:=-le; the   End; - Procedure init; -  varI,j,k,p:longint; -   begin + readln (m,n); -s:=0; t:=n+m+1; +      fori:=1  toM Do A      begin at Read (j); - Inc (TOT,J); - Add (s,i,j); -      End; -      fori:=1  toN Do -      begin in read (p); -         forj:=1  toP Do to         begin + read (k); -Add (K,i+m,1); the         End; * Readln; $Add (I+m,t,1);Panax Notoginseng      End; -   End; the  +  functionmin (a,b:longint): Longint; A   begin the     ifA<b ThenMin:=aElsemin:=b; +   End; -  function(x,nf:longint): Longint; $  varI,j,l,d,minh,ins:longint; $   begin -     ifX=t Thenexit (NF); -l:=NF; thei:=Cur[x]; -      whileI<>0  DoWuyi      begin the        if(date[i]>0) and(dis[point[i]]+1=DIS[X]) Then -            begin Wucur[x]:=i; -d:=(Point[i],min (l,date[i)); About Dec (date[i],d); $Inc (date[-i],d); - Dec (l,d); -              if(l=0)or(dis[s]=t+1) ThenExit (nf-l); -            End; Ai:=Next[i]; +      End; the     ifL=nf Then -       begin $minh:=t+1; thei:=Head[x]; the          whileI<>0  Do the          begin the            if(date[i]>0) and(Dis[point[i]]<minh) Then beginMinh:=dis[point[i]];ins:=i;End; -i:=Next[i]; in          End; thecur[x]:=ins; the Dec (vh[dis[x]]); About         ifvh[dis[x]]=0  Thendis[s]:=t+1; thedis[x]:=minh+1; the Inc (Vh[dis[x]); the       End; +aug:=nf-l; -   End; the  procedurePrint;Bayi  varI,j,k:longint; the   begin the      fori:=1  toM Do -      begin -j:=Head[i]; theWrite (I,':'); the         whileJ<>0  Do the         begin the           if(j>0) and(date[j]=0) ThenWrite (Point[j],' '); -j:=Next[j]; the         End; the Writeln; the      End;94   End; the Begin theAssign (input,'prog87.in'); Assign (output,'Prog87.out'); the reset (input); rewrite (output);98 Init; Aboutvh[0]:=t+1; -     forI:=s toT Docur[i]:=Head[i];101     whiledis[0]<t+1  DoInc (Flow,aug (S,maxlongint));102    ifFlow<>tot ThenWrite'No soluntion!')103                 ElsePrint;104 close (input); close (output); the End.106 107  

Question Bank Questions 2011-12-29

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.