Online Judge上陪审团选人问题用Java实现的一个AC解

原问题位于:http://poj.org/problem?id=1015

以下为问题描述的摘录:

In Frobnia, a far-away country, the verdicts in court trials are determined by a jury consisting of members of the general public. Every time a trial is set to begin, a jury has to be selected, which is done as follows. First, several people are drawn randomly from the public. For each person in this pool, defence and prosecution assign a grade from 0 to 20 indicating their preference for this person. 0 means total dislike, 20 on the other hand means that this person is considered ideally suited for the jury.
Based on the grades of the two parties, the judge selects the jury. In order to ensure a fair trial, the tendencies of the jury to favour either defence or prosecution should be as balanced as possible. The jury therefore has to be chosen in a way that is satisfactory to both parties.
We will now make this more precise: given a pool of n potential jurors and two values di (the defence's value) and pi (the prosecution's value) for each potential juror i, you are to select a jury of m persons. If J is a subset of {1,..., n} with m elements, then D(J ) = sum(dk) k belong to J
and P(J) = sum(pk) k belong to J are the total values of this jury for defence and prosecution.
For an optimal jury J , the value |D(J) - P(J)| must be minimal. If there are several jurys with minimal |D(J) - P(J)|, one which maximizes D(J) + P(J) should be selected since the jury should be as ideal as possible for both parties.
You are to write a program that implements this jury selection process and chooses an optimal jury given a set of candidates.

分析: 每一个candidate可以有被选和未被选两种可能。设O(p,q,diff,sum)表示: 在状态(diff,sum)下,从1, 2, ... p个候选人中选择q个作为陪审团成员的一个最优解, 如果

1)p被选中,那么剩下的q-1个候选人从p-1中选取的方案肯定也是最优的,即O(p,q,diff,sum) = O(p-1,q-1, diff + Ppscore - Pdscore, sum + Ppscore + Pdscore);

2)同样,如果p未被选中,那么剩下的q个候选人从p-1中选取的方案肯定也是最优的,即O(p,q,diff,sum) = O(p-1,q,diff,sum)。

这样最优解就是从这两种情况中选一个符合条件的最佳方案。

这里O(k,0) = {}; O(k,k)={1,2,...,k}

因此符合动态规划(DP)的最优原则。

在计算O(i,j,diff,sum)时并不需要考虑从n, n-1, ..., i+1的组合辩控和(即变量sum),因为如果有sum1>sum2,那么X + sum1 > X + sum2,而这里X就是从n, n-1, ..., i+1的组合辩控和。当然diff状态必须考虑,因为最终的最优解要求是绝对值,而不是简单和。本人一开始考虑sum,走了一些弯路。


计算顺序举例:如果在动态规划过程(遵循从1,2,...i计算顺序)计算到(i,j)-即从1...i个候选人中选择j个人作为陪审员时,当前状态 i=10,j=6,diff=-5(即代码中的s值: 可变范围diffMin~diffMax),pi=7(控方给第i个候选人的打分),di=4(辩方给第i个候选人的打分),此时有两个可能最优方案 i=9,j=6,diff=-5(即不选i,记为O(9,6,-5)=代码中的变量prevDs2)和i=9,j=5,diff=-5+(pi- di)=-2(即选i,记为O(9,5,-2)=代码中的变量prevDs1),接下来就要根据这两个可能解的|Diff(1, 2, ...,i)|最小以及Sum(1, 2, ...,i)最大决定取那个解作为最优方案,如果O(9,6,-5)和O(9,5,-2)的最优diff都等于-3,则需要比较下面两个辩控和: 1)第i (i=10)个候选人的辩控和dpiSum + O(9,5,-2)从1,2...9的辩控和prevDs1.sum; 2)O(9,6,-5)从1,2...9的辩控和prevDs1.sum。这里第二个方案中没有包含i。

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
/**
 * Author: ljs
 * 2011 - 05 - 14
 *  
 * see also: 
 */
public class Main {
	class DS{
		//the global optimal diff of both parties (prosecution and defense)
		//for the state (i,j,diff)
		short d;	
		//the current sum from 1 to i
		short sum;
		//the candidates(1~200): format: (1)(2)....(200)
		byte[] candNrs;		
	}
	class OptimalChoice {		
		DS[] diffTable;
		
		//the offset of the diff table
		int offsetDiff; 
		public OptimalChoice(DS[] diffTable,int offsetDiff){
			this.diffTable = diffTable;
			this.offsetDiff = offsetDiff;
		}
	}
	class Pair{
		short nr;
		short val;
		Pair(short nr,short val){
			this.nr =nr;
			this.val = val;
		}
	}	
	private OptimalChoice[] currLevel;
	private short[] P,D;
	//private short n;
	private short m;
	private int round;
	public void selectJury(short[] Ps, short[] Ds, short n, short m) {
		if (n < m || n != Ps.length || Ps.length != Ds.length)
			return;
				
		this.P = new short[n + 1];
		System.arraycopy(Ps, 0, P, 1, n);
		this.D = new short[n + 1];
		System.arraycopy(Ds, 0, D, 1, n);	
		//this.n = n;
		this.m = m;
			
		List<Pair> diffPairs = new LinkedList<Pair>();
		for(int i=1;i<=n;i++){
			diffPairs.add(new Pair((short)i, (short)(P[i] - D[i])));
		}
		Collections.sort(diffPairs,
				new Comparator<Pair>(){
					public int compare(Pair o1,Pair o2){
						if(o1.val>o2.val)
							return 1;
						else if(o1.val==o2.val)
							return 0;
						else
							return -1;
					}
				}
		);
		
		//Runtime rt = Runtime.getRuntime();
		
		OptimalChoice[] lastLevel =  null;
		for (short i = 1; i <= n; i++) {
			currLevel = new OptimalChoice[m+1];
			
			int remainCandidatesCount = n-i;	
			int removeIdx = -1;
			for(int k=0;k<diffPairs.size();k++){
				Pair p = diffPairs.get(k);
				if(p.nr == i){
					removeIdx = k;
					break;
				}
			} 		
			diffPairs.remove(removeIdx);			
			
			for (short j = 1; j <= m; j++) {
				int remainJurorsCount = m-j;
				if (i >= j && (remainCandidatesCount>=remainJurorsCount)) {	
				
					short diffMin = 0;
					short diffMax = 0;
												
					int u=0,v=diffPairs.size()-1;
					int cnt = 0;
					while(cnt<remainJurorsCount){
						diffMin += diffPairs.get(u).val;
						diffMax += diffPairs.get(v).val;
						u++;		
						v--;
						cnt++;
					}					
					
					short OFFSET_DIFF = (short)-diffMin;			
		
					short diffDim = (short)(diffMax - diffMin + 1);	
					
					
					DS[] diffTable = new DS[diffDim];			
					currLevel[j]=new OptimalChoice(diffTable,OFFSET_DIFF);
					
					//only one choice: select all candidates from 1...i						
					if (i == j) {  
						if(n-i==m-j && i<n){
							//go on to upper level
							break;					
							
						}else{
							short diffTotal = 0;
							short sumTotal = 0;
							for(int k=1;k<=i;k++){
								diffTotal += P[k] - D[k];
								sumTotal += P[k] + D[k];
							}			
							
							for(short s=diffMin;s<=diffMax;s++){
									//update the current table 
									DS dsNow = new DS();
									dsNow.d = (short)(diffTotal + s);
									dsNow.sum = (short)sumTotal;
									
									//dsNow.selected = true;
									//dsNow.selectAllPrev = true;
									byte[] candNrs = new byte[i];
									for(byte k=1;k<=i;k++){
										candNrs[k-1] = k;
									}			
						
									dsNow.candNrs = candNrs;
									
									//update the current table
									diffTable[s + OFFSET_DIFF] = dsNow;								
							}
						}						
					} else {
						/*
						O(i,j,diff,sum) = 
						 minabsOrmaxtotal(O(i-1,j-1,diff+pi-di), 
						 				   O(i-1,j,diff));
						 			if diff is equal, check the max in (sum_i + O(i-1,j-1).sum, O(i-1,j).sum)
						 */ 						
						// case 1: select i
						OptimalChoice prevOptimalChoice1 =  
							lastLevel[j - 1];
						int dpiDiff1 = P[i] - D[i];
						int dpiSum = P[i] + D[i];
						
						//case 2: not select i
						OptimalChoice prevOptimalChoice2 = lastLevel[j];
							
						for(short s=diffMin;s<=diffMax;s++){
								DS[] diffTable2 = prevOptimalChoice2.diffTable;						 			
				
								//get the prev optimal value
								DS prevDs2 = diffTable2[s + prevOptimalChoice2.offsetDiff];
														
								int diffNew1 = dpiDiff1 + s;	
												
								DS[] diffTable1 = null;
								if(prevOptimalChoice1 != null)
									diffTable1 = prevOptimalChoice1.diffTable;
								DS prevDs1 = null;
								if(diffTable1 != null)
									prevDs1 = diffTable1[diffNew1 + prevOptimalChoice1.offsetDiff];
								
								int diff1 = 0;			
						
								int sum1 = 0;
								if(prevDs1 ==null){
									diff1 = Math.abs(diffNew1);
									sum1 = dpiSum;
								}else{
									diff1 = Math.abs(prevDs1.d);	
									sum1 = dpiSum + prevDs1.sum;
								}
								//this case can't be possible
								//if(prevDs2 ==null){ 
								//	diff2 = Math.abs(s);
								//	sum2 = 0;
								//}else{
								int diff2 = Math.abs(prevDs2.d);	
								int sum2 = prevDs2.sum;
								//}
								
								
								int diffNow = s + OFFSET_DIFF;
								DS dsNow = new DS();
								boolean choice1 = true;
								if (diff1 < diff2) {
									choice1 = true;		
			
								}else  if (diff1 > diff2) {
									// select choice #2
									choice1 = false;												
								}else {				
					
									if(sum1 >= sum2){
										choice1 = true;
									}else{
										// select choice #2
										choice1 = false;
									}			
						
								}
								if(choice1){
									// select choice #1							
									if(prevDs1 == null){
										dsNow.d = (short)diffNew1;
									}else{
										dsNow.d = prevDs1.d;				
									}
									dsNow.sum = (short)sum1;
									//dsNow.selected = true;												
							
									byte[] candNrs = null;
									if(prevDs1 != null){
										candNrs = new byte[prevDs1.candNrs.length+1];									
											
										System.arraycopy(prevDs1.candNrs, 0, candNrs, 0, prevDs1.candNrs.length);		
										candNrs[candNrs.length-1] = (byte)i;
									}else{
										candNrs = new byte[1];
										candNrs[0]= (byte)i;
									}
									dsNow.candNrs = candNrs;		
								}else{
									//if(prevDs2 == null){
									//	dsNow.d = s;
									//}else{
									dsNow.d = prevDs2.d;											
									//}
									dsNow.sum = (short)sum2;												
			
									if(prevDs2 != null){
										byte[] candNrs = new byte[prevDs2.candNrs.length];										
										System.arraycopy(prevDs2.candNrs, 0, candNrs, 0, prevDs2.candNrs.length);																				
										dsNow.candNrs = candNrs;
									}				
								}
								diffTable[diffNow] = dsNow;	
						
						} 						
 
						
					}					
				} // i < j is invalid (e.g. n<m is not valid)
				
				//remove the last level's items from 1 to j-2:			
				if(lastLevel!= null && j>=1 && lastLevel[j-1] != null) {	
				
					DS[] diffTable = lastLevel[j-1].diffTable;
					for(int row=0;row<diffTable.length;row++){		
					
							diffTable[row] = null;			
		
					}
				
					//remove the DS items					
					lastLevel[j-1].diffTable = null;
					lastLevel[j-1] = null;		
				}
				// Collect garbage 
			    //rt.gc();
			}
			//long availMem = rt.freeMemory()/1000000;
		    //System.out.format("%d mb, i=%d%n", availMem,i);
			lastLevel = null;
			lastLevel = currLevel;
			//rt.gc();
			//System.gc();
		}				
	}
	
	
	public void setRound(int round) {
		this.round = round;
	}
	public void output(){
		OptimalChoice juryChoiceTable = currLevel[m];
		DS[] diffSumTable = juryChoiceTable.diffTable;
		int diff = 0;
		int offsetDiff = 0;		
		DS optimal = diffSumTable[diff + offsetDiff];
		
		int totalP=0;
		int totalD=0;
		byte[] candNrs = optimal.candNrs;
		
		List<Short> jurors = new ArrayList<Short>();
		for(int i=0;i<candNrs.length;i++){
			short candidateNr = (short)(candNrs[i] & 0x00ff);
			jurors.add(candidateNr);
			
			totalP += P[candidateNr];
			totalD += D[candidateNr];
		};
		Collections.sort(jurors);
		
		System.out.println("Jury #"+this.round);
		System.out.println("Best jury has value "+totalP + " for prosecution and value " + totalD +" for defence:");
		
		for(short jurorNr:jurors){
			System.out.print(" "+jurorNr);
		}	
	
		System.out.println();
		System.out.println();
	}
	public static void main(String[] args) throws Exception {
		
		
		List<short[]> PS =  new ArrayList<short[]>();
		List<short[]> DS =  new ArrayList<short[]>();
		List<Short> NS = new ArrayList<Short>();
		List<Short> MS = new ArrayList<Short>();
		short[] P=null;
		short[] D=null;
		short n=0,m=0;
		boolean jobsAvail = false;
		try{
			Scanner cin=new Scanner(System.in);
			String line = cin.nextLine();			
			if(line != null) {				
				boolean nextRound=true;
				int candidateLine=0;
				//int round=1;
				do{					
					line = line.trim();		
					if(line.length()==0){
						if(P != null && n >0){				
			
							PS.add(P);
							DS.add(D);
							NS.add(n);
							MS.add(m);
							jobsAvail = true;
							//round++;
						}
						
						//do the next round
						nextRound = true;				
		
						P = null;
						D = null;
					}else{			
						short[] pair = new short[]{-1,-1};
						
						String[] tokens = line.split(" ");
						for(int i=0,j=0;i<tokens.length;i++){
							String token = tokens[i].trim();
							if(token.length()>0 && j<2){
								pair[j++] = Short.parseShort(token);
							}
						}
						//end
						if(pair[0]==0 && pair[1]==0){			
				
							if(candidateLine<n){
								P[candidateLine] = pair[0];
								D[candidateLine++]=pair[1];
							}else{
								if(P != null){
									PS.add(P);
									DS.add(D);
									NS.add(n);
									MS.add(m);
									
									jobsAvail = true;
								}
								break;				
				
							}
						}else{
							if(nextRound){
								nextRound = false;
								n = pair[0];
								m = pair[1];
								P = new short[n];
								D = new short[n];
								candidateLine=0;
							}else{
								if(candidateLine<n){
									P[candidateLine] = pair[0];
									D[candidateLine++]=pair[1];
								}
							}
						}						
					}					
					line = cin.nextLine();
				}while(line !=null);
			}
		}catch(Exception e){
			throw e;
		}
		if(jobsAvail){			
			for(int i=0;i<PS.size();i++){
				Main js = new Main();
				js.setRound(i+1);
				js.selectJury(PS.get(i), DS.get(i), NS.get(i),MS.get(i));
				js.output();
			}
		}
	}
}

测试:

4 2 // sample input
 1  2
 2  3
 4  1
 6  2

5 3   // prosecution > defense
13 11
 3 17
15 20
 6 13
17  9

8 5   // prosecution < defense
 3  5
17 16
 6  0
17 10
 6 14
 3 19
 4 13
 0 17

8 4    // prosecution == defense
19 18
 5  9
 0  9
 5  0
 4  4
16  9
 4 15
20  5

2 1  // two solutions with diffence 1, but one of them
1 2  // has a larger value (version 1)
4 3

2 1  // two solutions with diffence 1, but one of them
4 3  // has a larger value (version 2)
1 2

2 1  // two solutions with diffence 1, but one of them
3 4  // has a larger value (version 3)
1 2

2 1  // two solutions with diffence 1, but one of them
2 1  // has a larger value (version 4)
3 4

18 7  // only differences +1,0,-1 occur with diffenent
 1  1 // sums (of values). Make sure that we are really
 1  2 // selecting the maximum sum.
 2  1
10 10
11 10
10 11
 7  7
 7  8
 8  7
14 14
14 15
15 14
 4  4
 4  5
 5  4
19 19
19 20
20 19

21 13 // all possible pairs of equal values: (0,0),...(20,20)
20 20 // again, there are many solutions with difference 0, but
19 19 // we want the one with maximum total value!
18 18
14 14
13 13
 5  5
 4  4
 3  3
12 12
10 10
 9  9
 8  8
17 17
16 16
15 15
 7  7
 6  6
11 11
 2  2
 1  1
 0  0

10 10 // n = m
 8 16
 9  6
 6  6
 2 15
 0 13
17  8
17  3
13 13
15 10
18  2

10 9  // n = m+1
12 13
16 17
 2  7
 1  9
 5  7
10  9
 9  8
 9 19
 2 10
 3 19

10 8  // n = m+2
14  4
18 17
20 12
10 16
 8 14
 1 16
 9 10
16 11
 4  2
10 16

10 5  // partition problem: note that the values of
 3  8 // both parties add up to 80. There exits a solution
15  8 // with diffence 0 iff the prosections values can be
11  8 // divided in two subsets with sum 40 each. This
 7  8 // example shows how to reduce BI-PARTITION to this
 1  8 // problem and therefore show its NP-completeness.
17  8
 8  8
 2  8
13  8
 3  8

1 1  // now for the boundary test: first comes n=m=1
9 11

1 1
7 3

1 1
5 5

1 1
0 0

1 1
0 20

1 1
20 0

1 1
20 20

20 20 // now comes n=m=20.
0 0   // first 20 times (0,0), then (0,20), (20,0) and (20,20)
0 0   // finally a random sample
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

20 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20

20 20
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0

20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20

20 20
 7 20
10  1
14 17
11 13
 3  5
19 19
 1 16
 4 18
 9  1
13  3
 7 16
 6  3
 1 20
 4  5
 6 13
 6  8
10  9
11 11
 0  7
12 15

200 20 // and now for maximum values: n = 200, m = 20.
0 0    // again a five test series as above
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

200 20
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0

200 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20
0 20

200 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20
20 20

200 20
12 20
10  0
13 17
15  1
 8 12
 4 12
 9  5
 3  3
13 18
13  6
12 11
10  6
 3  1
 6  1
20  2
20 18
19  2
12 12
 1  8
12  6
 6 11
11 16
11  0
 2  1
 7  6
15  6
13  7
16 17
 5 11
 0 14
17  8
10  9
12 14
 9  9
20  2
13  4
 5 19
17  0
 2 12
13  8
 4 17
 5  3
11 19
 6  9
 1  3
 5 10
18  0
 6  6
 2  8
20 11
 0  8
 5  1
12 17
17  8
 9 12
 9 10
 3  0
 0 19
20  9
15 16
 4  6
 1  1
19 13
 9 17
 0  8
 1  4
19 14
 1  6
16 14
12 12
19 18
19 19
 3 17
 9 17
 4  6
16 19
14  3
 9  4
13 19
 3 16
19  9
 0  2
 8  9
10 10
15  3
16  2
16  4
12  6
13  0
 8  0
11  8
18 15
18 18
 2 20
 7  2
14  1
 3  0
 0 15
11 16
 0 18
 1 17
11 11
 9  9
19  6
 6  1
18 13
19  8
 9  0
 2 18
16  9
18 12
10 13
12 13
16  5
 7 17
 5  4
13  8
 0  4
 8 19
12 14
 0  2
 6 19
 9  0
18  6
 7 19
18 19
15  7
 9 12
12  5
 0  1
15 15
 1 16
20 16
10 10
11  2
 7  4
16 12
16  0
 4  3
17 18
 8 14
13  7
 5 19
14 20
19 15
 5 19
18  7
 6  9
 0  2
 7  3
11 14
 7  0
 8  5
18 15
 0  2
11  2
11 17
11  8
 5 16
 5 13
12 12
 8  6
20 14
13 14
 0  1
10 15
12 17
14 15
 2  6
17 14
 6 13
10 10
13  6
 6 16
15 11
 4  5
15 18
11 13
19 20
 2  0
12  9
14  2
10 20
 0  7
16  2
16 13
20 17
14  6
 5 15
 7 19
17 10
 0 19
13 15
17 18
19  9
14  1
15  2
 8  8
 2 15
20  2

200 10 // and another large test, n=200,m=10
16 11
 9 10
 2 19
 2 18
 8  7
18  3
 9 16
10  3
16  3
 9 16
 4 14
10  0
10 13
 7  1
 5  3
 4 19
 9  1
 7  4
19 20
10  5
19 13
 9  5
12  4
18 12
 4 12
 0  8
 3  0
10 18
 6 19
 3  3
17  8
12 17
 5  3
16  4
 4 10
 8 18
17 17
18  9
 6  0
20  6
 8 13
 8  2
16 17
18  7
14  0
 0  3
14  0
10 11
 9 12
 7  9
 1  8
16 19
20 18
14 19
17 11
16  3
11 11
 5  1
19  4
 0 20
12 18
19 18
 7 16
 9  2
17 17
 5  7
 6 12
 9 18
17  4
 6  7
20  7
10  6
14  3
13 13
16 15
 6  0
19  7
15  6
16 19
20 17
17  0
12 18
 7  6
16  8
 5 17
10 15
 1  5
 4 19
 1  6
12  6
 4 10
 5  9
16  5
 8 17
 4  3
 1  6
 6  5
 3 19
13  6
11  1
 4  9
 1 19
 6  3
10 11
13  8
 0 13
 5  9
 1 10
13 19
15  0
 1 10
13  9
 6 13
16  3
 2 17
13 20
12  7
10 18
12 12
15 18
 4 18
14 10
17 18
11  2
 5  2
15 15
19 14
12  5
18 19
19 12
 5 17
 9 20
12  0
19 13
14  7
 2 16
 7 11
15 15
 8  6
 8  2
 1 13
18 15
 1  2
17 20
 4 19
 9 16
10 12
 7 12
 9  3
 5 14
 0 12
14 10
 1 11
12 18
16 16
10 15
 7  8
 9 10
13  7
11 14
 6  3
 7 20
16  4
17  1
 6  7
12 11
18  1
 6 19
10 15
15 12
 1 17
12  3
13 16
14 14
15  1
18  8
19 15
 6 15
12  9
14 16
 7  7
11  0
 1 20
16 13
15  3
 5 13
 9 11
12 15
20 16
 2 17
 1 19
17 15
12  5
16  2
 2  2
19  9
15  0
20 11
18 12
14  5


0 0
Jury #1
Best jury has value 6 for prosecution and value 4 for defence:
 2 3

Jury #2
Best jury has value 36 for prosecution and value 33 for defence:
 1 4 5

Jury #3
Best jury has value 50 for prosecution and value 53 for defence:
 2 3 4 5 7

Jury #4
Best jury has value 33 for prosecution and value 33 for defence:
 2 5 7 8

Jury #5
Best jury has value 4 for prosecution and value 3 for defence:
 2

Jury #6
Best jury has value 4 for prosecution and value 3 for defence:
 1

Jury #7
Best jury has value 3 for prosecution and value 4 for defence:
 1

Jury #8
Best jury has value 3 for prosecution and value 4 for defence:
 2

Jury #9
Best jury has value 111 for prosecution and value 111 for defence:
 4 10 11 12 16 17 18

Jury #10
Best jury has value 182 for prosecution and value 182 for defence:
 1 2 3 4 5 9 10 11 12 13 14 15 18

Jury #11
Best jury has value 105 for prosecution and value 92 for defence:
 1 2 3 4 5 6 7 8 9 10

Jury #12
Best jury has value 66 for prosecution and value 99 for defence:
 1 2 3 4 5 6 7 8 9

Jury #13
Best jury has value 93 for prosecution and value 94 for defence:
 1 2 3 4 6 8 9 10

Jury #14
Best jury has value 40 for prosecution and value 40 for defence:
 2 4 8 9 10

Jury #15
Best jury has value 9 for prosecution and value 11 for defence:
 1

Jury #16
Best jury has value 7 for prosecution and value 3 for defence:
 1

Jury #17
Best jury has value 5 for prosecution and value 5 for defence:
 1

Jury #18
Best jury has value 0 for prosecution and value 0 for defence:
 1

Jury #19
Best jury has value 0 for prosecution and value 20 for defence:
 1

Jury #20
Best jury has value 20 for prosecution and value 0 for defence:
 1

Jury #21
Best jury has value 20 for prosecution and value 20 for defence:
 1

Jury #22
Best jury has value 0 for prosecution and value 0 for defence:
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Jury #23
Best jury has value 0 for prosecution and value 400 for defence:
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Jury #24
Best jury has value 400 for prosecution and value 0 for defence:
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Jury #25
Best jury has value 400 for prosecution and value 400 for defence:
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Jury #26
Best jury has value 154 for prosecution and value 220 for defence:
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Jury #27
Best jury has value 0 for prosecution and value 0 for defence:
 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200

Jury #28
Best jury has value 400 for prosecution and value 0 for defence:
 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200

Jury #29
Best jury has value 0 for prosecution and value 400 for defence:
 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200

Jury #30
Best jury has value 400 for prosecution and value 400 for defence:
 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200

Jury #31
Best jury has value 350 for prosecution and value 350 for defence:
 1 16 28 60 71 72 76 92 93 126 133 140 144 145 154 163 177 179 187 194

Jury #32
Best jury has value 182 for prosecution and value 182 for defence:
 19 43 53 62 79 80 123 129 144 189

转载于:https://www.cnblogs.com/ljsspace/archive/2011/06/05/2073355.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值