The main effect of the topic
Given a tree, select as few nodes as possible so that each node that is not selected is adjacent to at least one of the selected nodes.
Ideas
The classic tree-type DP is said to be the smallest vertex overlay.
F[u][0]: Indicates that the I point is not selected, overwriting the minimum point of this subtree
F[U][1]: Select the I point, covering the minimum point of this subtree
For the U-point, if you select this point, then his byte point can be selected or not
If you do not select the point, then its child nodes must be selected! At first I thought it was OK to select at least one byte point, but it was wrong!
Because the following situation may occur:
Vertex 1 is not selected, 2 of the child nodes are selected, but 3 have no adjacent nodes to choose from.
So we can get the equation of state transition:
F[U][1] = sum{min{f[v][0], f[v][1]}, V is a child node of U
F[u][0] = sum{F[v][1], V is a child node of U
Code
/**========================================== * is a solution for ACM/ICPC problem * * @problem: UVA 1292-str Ategic game * @type: DP * @author: Shuangde * @blog: blog.csdn.net/shuangde800 * @email: zengshuangde@gmail.com *========= ==================================*/#include <iostream> #include <cstdio> #include <algorithm> #
include<vector> #include <queue> #include <cmath> #include <cstring> using namespace std;
typedef long long Int64;
const int INF = 0X3F3F3F3F;
Const double PI = ACOs (-1.0);
const int MAXN = 1510;
int n;
int f[maxn][2];
BOOL VIS[MAXN];
vector<int>adj[maxn]; void Dfs (int u) {Vis[u] = true; F[u][0] = 0; f[u][1] = 1; for (int i=0; i<adj[u].size (); ++i) {int v = adj[u][i]; if (Vis
[v]) continue;
DFS (v);
F[u][1] + min (f[v][1], f[v][0]);
F[u][0] + = f[v][1];
int main () {while (~SCANF ("%d", &n) && N) {for (int i=0; i<=n; ++i) adj[i].clear (); for (int i=0; i<n; ++i){int u, x; scanf ("%d: (%d)", &u, &x);
for (int j=0, v j<x; ++j) {scanf ("%d", &v); Adj[u].push_back (v); Adj[v].push_back (u);}
memset (Vis, 0, sizeof (VIS));
DFS (0);
printf ("%d\n", Min (f[0][0), f[0][1]);
return 0; }