天天看点

Educational Codeforces Round 114 (Rated for Div. 2) D. The Strongest Build 暴力 + bfs题意:思路:

传送门

文章目录

  • 题意:
  • 思路:

题意:

你有 n n n个装备槽,每个槽里面有 c i c_i ci​个力量加成,对于每个槽只能选一个力量加成,现在给你 m m m个力量组合 [ b 1 , b 2 , . . . , b n ] [b_1,b_2,...,b_n] [b1​,b2​,...,bn​]代表这个力量组合是不能选择的。问你每个槽选择一个力量之后最大的的力量总和是多少。保证有解。

n ≤ 10 , 1 ≤ c i ≤ 2 e 5 n\le 10,1\le c_i\le 2e5 n≤10,1≤ci​≤2e5

c i c_i ci​总和不超过 2 e 5 2e5 2e5

思路:

可以知道,总共的情况就是 ∏ i = 1 n c i \prod_{i=1}^nc_i ∏i=1n​ci​,由于有解,所以这个显然是大于 m m m的,考虑暴力找状态。

一开始想了个假算法,就是每次找所有槽中值最小的,显然不对,考虑到 m ≤ 2 e 5 m\le 2e5 m≤2e5,所以如果我们直接从当前状态枚举 n n n个槽去掉了一个状态,将这些状态压入队列中,一定可以找到最优解,但是队列显然会爆掉,考虑到当找到一个能取的集合,那么这个集合的子集合都没有用了,所以这个时候不需要扩展,而且会遍历到很多重复的集合,所以需要去重,所以这样直接搞就好了,复杂度我不是很会算。。

// Problem: D. The Strongest Build
// Contest: Codeforces - Educational Codeforces Round 114 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1574/problem/D
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;

//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;

int n,m;
int ed[20];
vector<int>v[20],ans;
set<pair<int,vector<int>>>s;
map<vector<int>,int>mp,st;

int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		int c; scanf("%d",&c);
		while(c--) {
			int x; scanf("%d",&x);
			v[i].pb(x);
		}
	}
	scanf("%d",&m);
	for(int i=1;i<=m;i++) {
		vector<int>v;
		for(int i=1;i<=n;i++) {
			int x; scanf("%d",&x);
			v.pb(x);
		}
		mp[v]=1;
	}	
	
	int sum=0;
	for(int i=1;i<=n;i++) ans.pb(v[i].size());
	queue<vector<int>>q;
	q.push(ans); int now=0;
	st[ans]=1;
	while(q.size()) {
		auto x=q.front(); q.pop();
		if(!mp.count(x)) {
			int all=0;
			for(int i=1;i<=n;i++) all+=v[i][x[i-1]-1];
			if(all>sum) sum=all,ans=x;
			continue;
		}
		for(int i=1;i<=n;i++) {
			if(x[i-1]>1) {
				x[i-1]--;
				if(st.count(x)) {
					x[i-1]++;
					continue;
				}
				q.push(x);
				st[x]=1;
				x[i-1]++;
			} 
		}
	}
	for(auto x:ans) cout<<x<<' '; puts("");
	
	


	return 0;
}
/*
3 1 2 3
2 1 5
3 2 4 6
2
3 2 3
2 2 3
*/









           

继续阅读