// Topcoder SRM 466 DIV 2, L1: LotteryTicket
import java.util.*;
class TopcoderSolution {
public static void main(String[] args) {
LotteryTicket obj = new LotteryTicket();
System.out.println(
obj.buy(10, 1, 5, 10, 50)
);
}
}
// change to public before submit
class LotteryTicket {
public String buy(int price, int b1, int b2, int b3, int b4) {
int[] b = new int[] { b1, b2, b3, b4 };
for (int i = 0; i < 16; i++) {
int sum = 0;
for (int j = 0; j < 4; j++) {
if ((i >> j & 1) == 1) {
sum += b[j];
}
}
if (sum == price) {
return "POSSIBLE";
}
}
return "IMPOSSIBLE";
}
}
No comments:
Post a Comment