#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<string> #include<vector> #include<queue> voiddfs(int u, int sum);
usingnamespace std;
constint N = 25, M = 45; int q[N][2], cnt; int st[N], full[M]; int res = 0; int n, m;
intmain(){ cin >> n >> m; for (int i = 0; i < n; ++i) cin >> q[i][0] >> q[i][1]; for (int i = 1; i <= m; ++i) full[i] = 1; cnt = m / 2; // 最多可以满意的顾客数 dfs(0, 0); cout << res << endl; }
// 当前顾客号,已选人数 voiddfs(int u, int sum){ if (sum <= cnt) res = max(res, sum); elsereturn;
for (int i = u; i < n; ++i) { int x1 = q[i][0], x2 = q[i][1]; if (full[x1] == 0 || full[x2] == 0) continue; full[x1] --, full[x2] --; sum ++; dfs(u + 1, sum); sum --; full[x1] ++, full[x2] ++; } }
// // Created by 86139 on 2022/3/12. // #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<string> #include<vector> #include<queue>
usingnamespace std;
constint N = 10010; int dp[N][13]; int q[N];
/** 2 4 2 1 1 2 2 */ intmain(){ int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; ++i) { scanf("%d", &q[i]); } // dp[i][j] 表示 第i秒在第j个房间的最小消耗 memset(dp, 0x3f, sizeof dp); dp[1][1] = 0; //第1秒肯定没有消耗 for (int i = 2; i <= n; ++i) dp[1][i] = 1; for (int i = 2; i <= m; ++i) for (int j = 1; j <= n; ++j) if (q[i] != j) { // 第 i 秒肯定不能选a[i]这个房间 for (int k = 1; k <= n; ++k) { if (j != k) dp[i][j] = min(dp[i][j], dp[i - 1][k] + 1); else dp[i][j] = min(dp[i][j], dp[i - 1][k]); } } int res = 1e9; for (int i = 1; i <= n; ++i) { res = min(res, dp[m][i]); } printf("%d\n", res); }