Noi 1980 candidates for Jury (POJ1015)

Source: Internet
Author: User
Tags one more line
1980: a jury candidate.

Total time limit:

1000ms

Memory Limit:

65536kB

Describe

It is up to the jury to decide whether the suspect is guilty in a distant country Frobnia. The jury was chosen by the judge from the public. A random selection of N-individuals as a jury candidate, and then from the N-person selected m people to form a jury. The way to choose m people is:

The prosecution and the defence will rate all candidates based on their liking for the candidate, with a score of 0 to 20. To be fair, the judge's principle of electing a jury is: The chosen M-Man must satisfy the absolute minimum of the difference between the defense's total and the total. If there are multiple options for the difference between the defense score and the control total score of the same absolute value, then the selection of the two sides of the total sum of the largest scheme can be.

Input

The input contains multiple sets of data. The first line of data for each group is two integers n and m,n is the number of candidates, and M is the number of jurors. Note, 1<=n<=200, 1<=m<=20 and M<=n. The next n lines, each line represents a candidate's information, it contains 2 integers, successively the prosecution's and the defense's rating of the candidate. The candidates are numbered starting from 1, as they appear. Two valid sets of data are separated by a blank line. The last set of data n=m=0

Output

For each set of data, the first line is output, indicating the group number to which the answer belongs, such as ' Jury #1 ', ' Jury #2 ', and so on. The next line is to output the jury's total and defense scores as an example. One more line. To output the number of each member of the jury in ascending order, the two member numbers are separated by a space. Each set of output data must end with a blank line.

Sample input

4 2

1 2

2 3

4 1

6 2

0 0

Sample output

Jury #1

Best jury have value 6 for prosecution and value 4 for defence:

2 3

Source

Southwestern European Regional Contest 1996, POJ 1015, program Design Internship 2007

Ideas

Dp.

D[I][J] Indicates that the election of the individual and the difference between the defence and the prosecution is J when the greatest defense and.

Set P to the defense score D for the control fraction, V (i) =p[i]-d[i],s (i) =p[i]+d[i]

Like the following transfer type:

d[i][j]=max{d[i-1][j-v (k)]+s (k)}

The transfer type represents the I-candidate K, and K must satisfy the best choice of d[i-1][j-v (k)) did not appear.

Using Path[i][j] to record the difference of J when the first person selected, on the one hand to check whether K has appeared, on one hand to facilitate the construction of the solution.

The difference is negative so the difference is all offset by n units.

Code

 1 #include <iostream> 2 #include <cstring> 3 #include <vector> 4 #include <cstdio> 5 #include <
 Algorithm> 6 using namespace std;
 7 8 const int MAXN = 400+10;
9 int D[25][5*MAXN];
int PATH[25][5*MAXN];
int P[MAXN],D[MAXN];
int n,m;
Vector<int> ans; Ios::sync_with_stdio int Main () {(false); int kase=0; while (Cin>>n>>m && (         N&&m) {for (int i=1;i<=n;i++) cin>>p[i]>>d[i];-memset (d,-1,sizeof (D)); 23
memset (path,0,sizeof (path));
n=m*20 int;
d[0][n]=0;                     i=0;i<m;i++ (int) {j=0;j<=2*n;j++) if (d[i][j]>=0) 28 {29                             for (int k=1;k<=n;k++) {if (D[i][j]+p[k]+d[k]>d[i+1][j+p[k]-d[k]]) {31
int ti=i,tj=j;  while (ti>0 && path[ti][tj]!=k) {33                               TJ-=P[PATH[TI][TJ]]-D[PATH[TI][TJ]];
ti--; (!ti) {PNS D[i+1][j+p[k]
-D[K]]=D[I][J]+P[K]+D[K];
Path[i+1][j+p[k]-d[k]]=k;          39} 40} 41} 42} 43} 44
int i=n,j=0,k,totp=0,totd=0;
(d[m][i+j]<0&&d[m][i-j]<0) j + +;
if (D[m][i+j]>d[m][i-j]) k=i+j;
K=i-j else;
Ans.clear (); (i=1;i<=m;i++) {ans.push_back (path[m-i+1][k]); k-=p[ans[i-1]]-
D[ans[i-1]]; TotP + = p[ans[i-1]];
TOTD + = d[ans[i-1]];
(Ans.begin (), Ans.end ());
Jury printf ("#%d\n", ++kase); $ printf ("Best jury have value%d for prosecution and value%d for DefencE:\n ", TOTP,TOTD);
i=0;i<m;i++ ("%d", Ans[i])   
printf ("\ n");
0}; 63}

 

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.