1.

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS11
* Problem: 10344 23 out of 5
* Link:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1285
*
* @author Rolf Schirm
* @version 1.0, 04/27/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 2.272
*/
public class Main {
/**
* Array with the five input numbers
*/
private static final int[] array = new int[5];

/**
* Flag to lock each number
*/
private static final boolean[] contains = new boolean[5];

/**
* Result
*/
private static boolean possible;

public static void main(String... args) throws Exception {
final BufferedReader scan = new BufferedReader(new
InputStreamReader(System.in));

String line;
while((line = scan.readLine()) != null && !line.equals("0 0 0 0 0")) {
if(!line.isEmpty()) {
// Write input numbers into array
String[] split = line.split(" ");
for(int i = 0; i < 5; i++) {
array[i] = Integer.parseInt(split[i]);
}

// Recursive calculation
possible = false;
calc(0, 0);

// Print the result
if(possible) {
System.out.println("Possible");
} else {
System.out.println("Impossible");
}
}
}
}

private static void calc(int len, int number) {
// Check if its complete
if(len == 5) {
if(number == 23) {
possible = true;
}
} else {
// Increment length
len++;

// Look over all numbers until a solution is found
for(int i = 0; i < 5 && !possible; i++) {
// Check if the element is unused
if(!contains[i]) {
// Lock the element
contains[i] = true;

// Get the element
final int element = array[i];

// First element
if(len == 1) {
calc(len, element);
} else {
// Calculate the number with each operator until a solution is found
for(int operator = 0; operator < 3 && !possible; operator++) {
switch(operator) {
case 0:
// Addition
calc(len, number + element);
break;

case 1:
// Subtraction
calc(len, number - element);
break;

case 2:
// Multiplication
calc(len, number * element);
break;
}
}
}

// Unlock the element
contains[i] = false;
}
}
}
}
}


----------------------------------------------------------------------------





1.
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 10344 - 23 out of 5
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1285
*
* @author Evgeni Pavlidis
* @version 1.0, 05/20/2010
*
* Method : Backtracking
* Status : Accepted
* Runtime: 1.748
*/


import java.io.*;
import java.util.*;

class Main {

private static int[] a = new int[5];
private static boolean[] available = new boolean[5];

private static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

private static int nextInt() throws Exception
{
st.nextToken();
return (int)st.nval;
}

private static boolean isPossible(int value, int step)
{
if(step == 5 && value == 23)
return true;

if(Math.abs(value) > 200)
return false;

for(int i = 0; i < 5; i++)
if(available[i])
{
available[i] = false;

if(isPossible((step == 0 ? 1 : value) * a[i], step+1) ||
isPossible(value + a[i], step+1) ||
isPossible((step == 0 ? a[i] : (value - a[i])), step+1) )
return true;

available[i] = true;
}

return false;
}

public static void main(String...args) throws Exception
{
int abort;

while(true)
{
abort = 0;

for(int i = 0; i < 5; i++)
{
a[i] = nextInt();
available[i] = true;
}

for(int i: a)
abort += Math.abs(i);

if(abort == 0)
break;

System.out.println((isPossible(0, 0)? "Possible" : "Impossible"));
}
}
}