AT_abc200_d [ABC200D] Happy Birthday! 2 Solution

AT_abc200_d [ABC200D] Happy Birthday! 2 Solution

Luogu Portal

AT Portal

train of thought

We can prove that as long as N ≥ 8 N\ge 8N8 , then there must be a solution.

The proof is as follows:

  • 8 8 The subsequences that can be composed of 8 elements are 2 8 − 1 = 255 2^8-1=255281=255 species. (Each element can be selected or not selected, remove all unselected cases)

  • According to the drawer principle, we put the 255 255255 seed sequences according to their division by200 200If the remainder of 200 is put into drawers respectively, then at least two subsequences are in one drawer, that is, there must be legalAAA andBBB

N < 8 N<8 N<At 8 o'clock, we violently enumerate all possibilities;

This N ≥ 8 N \ge 8N8 , we violently enumerate any8 of them 8All the possibilities composed of 8 elements can find the solution .

the code

#include <bits/stdc++.h>
#define lowbit(x) x & (-x)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO {
    
    
	inline int read() {
    
    
		register int x = 0, f = 1;
		register char c = getchar();
		while (c < '0' || c > '9') {
    
    
			if(c == '-') f = -1;
			c = getchar();
		}
		while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
		return x * f;
	}
	inline void write(int x) {
    
    
		if(x < 0) putchar('-'), x = -x;
		if(x > 9) write(x / 10);
		putchar(x % 10 + '0');
		return;
	}
}
inline void print(const vector<int>& v) {
    
    
	printf("%llu", v.size());
	for(int x: v) {
    
    
		printf(" %d", x + 1);
	}
	putchar('\n');
}
using namespace fastIO;
int a[15];
vector<int> bkt[200];
int main() {
    
    
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	n = read();
	if(n > 8) {
    
    
		n = 8;	
	}
	for(int i = 0; i < n; i ++) {
    
    
		scanf("%d", a + i);
	}
	int lim = 1 << n;
	for(int st = 0; st < lim; st ++) {
    
    
		int s = 0;
		vector<int> pos;
		for(int i = 0; i < n; i ++) {
    
    
			if(st >> i & 1) {
    
    
				s = (s + a[i]) % 200;
				pos.push_back(i);
			}
		}				
		if(!bkt[s].empty()) {
    
    
			puts("Yes");
			print(bkt[s]);
			print(pos);
			return 0;
		}
		else bkt[s] = pos;
	}
	puts("No");
	return 0;
}

Guess you like

Origin blog.csdn.net/ZH_qaq/article/details/130456455