37 pts 求助
  • 板块P1283 平板涂色
  • 楼主ademik
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/3/29 16:15
  • 上次更新2023/10/23 20:08:11
查看原帖
37 pts 求助
750173
ademik楼主2023/3/29 16:15
# include <cstdio>
# include <iostream>
# include <algorithm>
# include <cstring>
# include <queue>
using namespace std;
const int N = 150, Inf = 0x3f3f3f3f;
struct node {
	int x1, y1, x2, y2, co;
} a[N];
int n;
int mark[N][N], ans = Inf, vis[N];
bool ok[N];
bool pd(int x)
{
	if(a[x].x1 == 1) return true;
	for(int i = a[x].y1; i <= a[x].y2; i ++) {
		if(!ok[mark[a[x].x1 - 1][i]]) return false;
	}
	return true;
}
void dfs(int co, int s, int step)
{
	if(step >= ans) return;
	if(s == (1 << (n - 1)) - 1) {
		ans = min(ans, step);
		return;
	}
	for(int i = 1; i <= n; i ++) {
		if(pd(i) && (s & (1 << (i - 1))) == 0) {
			ok[i] = true;
			dfs(a[i].co, s | (1 << (i - 1)), step + (co == a[i].co ? 0 : 1));
			ok[i] = false;
		}
	}
	return;
}
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >>n;
	for(int i = 1; i <= n; i ++) {
		cin >>a[i].y1 >>a[i].x1 >>a[i].y2 >>a[i].x2 >>a[i].co;
		a[i].x1 ++; a[i].y1 ++;
		for(int j = a[i].x1; j <= a[i].x2; j ++) {
			for(int k = a[i].y1; k <= a[i].y2; k ++) {
				mark[j][k] = i;
			}
		}
		//a[i].x2 --; a[i].y2 --;
	}
	for(int i = 1; i <= n; i ++) {
		if(a[i].x1 == 1) {
			ok[i] = true;
			dfs(a[i].co, 1 << (i - 1), 1);
			memset(ok, 0, sizeof(ok));
		} 
	}
	cout <<ans <<endl;
	return 0;	
}
2023/3/29 16:15
加载中...