Loading

Codeforces Round #717 (Div. 2) C. Baby Ehab Partitions Again(思维)

Baby Ehab was toying around with arrays. He has an array a of length n. He defines an array to be good if there's no way to partition it into 2 subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in 𝑎a so that it becomes a good array. Can you help him?

A sequence b is a subsequence of an array 𝑎a if 𝑏b can be obtained from a by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into 2 subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.

Input

The first line contains an integer n (2≤n≤100) — the length of the array 𝑎a.

The second line contains 𝑛n integers a1, a2, ……, an (1≤ai≤2000) — the elements of the array a.

Output

The first line should contain the minimum number of elements you need to remove.

The second line should contain the indices of the elements you're removing, separated by spaces.

We can show that an answer always exists. If there are multiple solutions, you can print any.

Examples

input

Copy

4
6 3 9 12

output

Copy

1
2

input

Copy

2
1 2

output

Copy

0

首先判断是否已经是好的序列,直接背包dp判断即可(当然如果和为奇数直接输出0)。然后只要序列中有一个奇数,就删掉这个数即可,因为删掉以后sum就为奇数了。其次如果序列全是偶数,则将每个数除以所有数的GCD,得到的序列必然含有奇数,再从里面找奇数删除即可。原理就是两个相等的子序列同乘一个数还是相等的。

#include <bits/stdc++.h>
using namespace std;
int n;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
bool dp[105][200005];
int a[105], b[2005];
int main() {
	cin >> n;
	int sum = 0;
	memset(b, 0, sizeof(b));
	memset(dp, 0, sizeof(dp));
	int GCD = a[1];
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
		b[a[i]]++;
		GCD = gcd(GCD, a[i]);
	}
	for(int i = 1; i <= n; i++) {
		dp[i][a[i]] = 1;//必须先排序再初始化
		dp[i][0] = 1;
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= 200000; j++) {
			if(j - a[i] >= 0) dp[i][j] |= dp[i - 1][j - a[i]];
			dp[i][j] |= dp[i - 1][j];//不要忘记当前不选的情况
		}
	}
	if(sum & 1 || !dp[n][sum / 2]) {
		cout << 0;
		return 0;
	}
	cout << 1 << endl;
	for(int i = 1; i <= n; i++) {
		if(a[i] & 1) {
			cout << i;
			return 0;
		}
	}
	for(int i = 1; i <= n; i++) a[i] /= GCD;
	for(int i = 1; i <= n; i++) {
		if(a[i] & 1) {
			cout << i;
			return 0;
		}
	}
	return 0;
}
//2 3 5 10
//2 4 4 10 12

posted @ 2021-04-29 21:13  脂环  阅读(114)  评论(0编辑  收藏  举报