1 / 2
Feb 2021

so here’s a problem I can’t solve on bit manipulation:

i cannot think of anything other than brute force:

import java.util.Scanner;
class FoodExhibition {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m[] = new int[n];
		for (int i = 0; i < n; ++i) {
			m[i] = sc.nextInt();
		}
		int t[] = new int[n];
		for (int i = 0; i < n; ++i) {
			t[i] = 0;
		}
		recurse(m, 0, 0, 0, t);
		for (int i = 0; i < n; ++i) {
			System.out.print(t[i] + " ");
		}
	}
	public static void recurse(int m[], int i, int meals, int tasteValue, int t[]) {
		if (i == m.length) {
			if (meals > 0) {
				t[meals - 1] = (int) (((long) t[meals - 1] + (long) tasteValue) % 1000000007);
			}
		} else {
			recurse(m, i + 1, meals, tasteValue, t);
			recurse(m, i + 1, meals + 1, (tasteValue ^ m[i]), t);
		}
	}
}

Can anyone help me out with this problem?

  • created

    Feb '21
  • last reply

    Feb '21
  • 1

    reply

  • 535

    views

  • 1

    user

Suggested Topics

Want to read more? Browse other topics in Online Judge System or view latest topics.