POJ 1463 strategy IC game minimum point coverage, tree-like DP

Source: Internet
Author: User
/* It should be a minimum point coverage problem. You can split the points and use a bipartite graph. Here we use the tree-like DP to solve the leaf node I. Obviously: DP [I] [0] = 0, DP [I] [1] = 1 otherwise, DP [I] [0] = sum (DP [J] [1], J is the child of I ), DP [I] [1] = sum (min (DP [J] [0], DP [J] [1]) */# include <vector> # include <map> # include <set> # include <deque> # include <stack> # include <bitset> # include <algorithm> # include <functional> # include <numeric> # include <utility> # include <sstream> # include <iostream> # include <iomanip> # include <cstdio> # include <queue> # InCl Ude <cmath> # include <cstdlib> # include <cstring> # include <ctime> # include <string> using namespace STD; const int n = 1600; int N; struct edge {int V, next;} edge [2 * n]; int first [N], E; int DP [N] [2]; void addedge (int u, int v) {edge [e]. V = V; edge [e]. next = first [u]; first [u] = e ++; edge [e]. V = u; edge [e]. next = first [v]; first [v] = e ++;} void Init () {int X, num, Y; E = 0; For (INT I = 0; I <n; I ++) {first [I] =-1; DP [I] [0] = 0; DP [I] [1] = 1 ;} for (INT I = 0; I <n; I ++) {scanf ("% d :( % d)", & X, & num); For (Int J = 0; j <num; j ++) {scanf ("% d", & Y); addedge (x, y) ;}} int DFS (int x, int FA) {int flag = 1; for (int K = first [X]; k! =-1; k = edge [K]. Next) {If (edge [K]. V! = FA) {DFS (edge [K]. v, x); DP [x] [1] + = min (DP [edge [K]. v] [0], DP [edge [K]. v] [1]); DP [x] [0] + = DP [edge [K]. v] [1]; flag = 0 ;}} void solve () {DFS (0,-1); cout <min (DP [0] [0], DP [0] [1]) <Endl;} int main () {While (scanf ("% d", & N )! = EOF) {Init (); solve ();}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.