日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【dfs】民生问题(2011特长生 T4)

發(fā)布時間:2023/12/3 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【dfs】民生问题(2011特长生 T4) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目大意

有n個問題,m個人,每個人可以解決一些問題,問最少選多少個人可以解決所有問題


解題思路

如果一個人解決的問題被別的人包括,那么可以把這個人丟掉

對于一個問題只能由一個人解決,那么直接選這個人

然后枚舉每個問題被誰解決即可


代碼

#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define ll long long #define N 100 using namespace std; int n, m, x, y, g, pp, ans, tot, dg[N], uf[N], p[N], head[N], a[N][10]; struct rec {int to, next; }e[N*6]; void add(int x, int y) {e[++tot].to = y;e[tot].next = head[x];head[x] = tot; } void dfs(int x, int y) {if (y >= ans) return;if (x > n){ans = min(ans, y);return;}if (p[x]){dfs(x + 1, y);return;}for (int i = head[x]; i; i = e[i].next)if (!uf[e[i].to]){for (int j = 1; j <= a[e[i].to][0]; ++j)p[a[e[i].to][j]]++;dfs(x + 1, y + 1);for (int j = 1; j <= a[e[i].to][0]; ++j)p[a[e[i].to][j]]--;}return; } int main() { ans = 60;scanf("%d%d", &n, &m);for(int i = 1; i <= m; ++i){scanf("%d", &x);a[i][0] = x;for (int j = 1; j <= x; ++j){scanf("%d", &a[i][j]);add(a[i][j], i);}sort(a[i] + 1, a[i] + 1 + x);}for (int i = 1; i <= m; ++i)for (int j = 1; j <= m; ++j)//i包括j{if (i == j) continue;pp = 1;x = 1;y = 1;while(x <= a[i][0]){while (a[i][x] == a[j][y] && y <= a[j][0]) y++;if (y > a[j][0]) break;x++;}if (y <= a[j][0]) pp = 0;if (a[i][0] == a[j][0] && i < j) pp = 0;if (pp) uf[j] = 1;}for (int i = 1; i <= m; ++i)if (!uf[i])for (int j = 1; j <= a[i][0]; ++j)dg[a[i][j]]++;for (int i = 1; i <= n; ++i)if (dg[i] == 1 && !p[i])//只能由一個人解決{g++;for (int j = head[i]; j; j = e[j].next)if (!uf[e[j].to]){for (int k = 1; k <= a[e[j].to][0]; ++k)p[a[e[j].to][k]]++;}}dfs(1, g);printf("%d", ans);return 0; }

總結(jié)

以上是生活随笔為你收集整理的【dfs】民生问题(2011特长生 T4)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。