helloneo wrote:
On that case, 2 can be also reliable..

Yes, 2 can be reliable. Please tell me whether my following logic to solve the problem is incorrect:
for each input of X and Y,
(
BX = The current state of X
BY = The current state of Y
If BX is not set and BY is not set
=> set BX = 1 or 0
If BX is set but BY is not set
{
BX = 1 and Y > 0 => BY = 1
BX = 1 and Y < 0 => BY = 0
BX = 0 => BY = 1 or 0
}
else If BX not is set but BY is set
{
BY = 1 and Y > 0 => BX = 1 or 0
BY = 0 and Y > 0 => BX = 0
BY = 1 and Y < 0 => BX = 0
BY = 0 and Y < 0 => BX = 1 or 0
}
else If BX is set and BY is set
{
BX = 1 and Y > 0 and BY = 1 => OK
BX = 1 and Y < 0 and BY = 0 => OK
BX = 0 and BY = 1 or 0 => OK
Otherwise, not OK => prune this solution
}
)
If any BX is not set after parsing all input, set BX = 1
=> Finally check the number of 1 set, and output the max one.
If I applied the above logic to the sample input, we get:
First case: B1 = 1
1 -3 => 1_0 (underscore represents the BX is not set)
2 -3 => 110 or 100
3 1 => 110 or 100
2 2 => 110 or 100
7 -1 =>110___0 or 100___0
4 3 => 1100__0 or 1000__0
Max is:
-> 1100110 .... (13 1's)
-> So this case, number of 1's is 17
Second case: B1 = 0
1 -3 => 0_0 or 0_1
2 -3 => 010 or 000 or 001
3 1 => check contradiction => 010 or 000 (001 is contradict with 1 -3)
2 2 => 010 or 000
7 -1 => 010___1 or 010___0 or 000___1 or 000___0
4 3 => 0100__1 or 0100__0 or 0000__1 or 0000__0
Max is:
-> 0100111 ... (13 1's)
-> So this case, number of 1's is also 17.
How can the maximum number of informants be 18? Thanks.