题目传送门

 /*
题解:选择一个点,它相邻的点都当做被选择,问最少选择多少点将所有点都被选择
树形DP:dp[i][0/1]表示当前点选或不选,如果选,相邻的点可选可不选,取最小值
*/
/************************************************
* Author :Running_Time
* Created Time :2015-8-12 10:54:05
* File Name :UVA_1292.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
vector<int> G[MAXN];
bool vis[MAXN];
int dp[MAXN][];
int n; void DFS(int u) {
vis[u] = true;
for (int i=; i<G[u].size (); ++i) {
int v = G[u][i];
if (vis[v]) continue;
DFS (v);
dp[u][] += min (dp[v][], dp[v][]);
dp[u][] += dp[v][];
}
} int main(void) { //UVA 1292 Strategic game
while (scanf ("%d", &n) == ) {
for (int i=; i<n; ++i) G[i].clear ();
memset (dp, , sizeof (dp));
for (int i=; i<n; ++i) dp[i][] = ;
memset (vis, false, sizeof (vis)); for (int i=; i<=n; ++i) {
int u, v, num; scanf ("%d:(%d)", &u, &num);
for (int j=; j<=num; ++j) {
scanf ("%d", &v);
G[u].push_back (v); G[v].push_back (u);
}
} DFS ();
printf ("%d\n", min (dp[][], dp[][]));
} return ;
}

树形DP UVA 1292 Strategic game的更多相关文章

  1. UVa 1292 - Strategic game (树形dp)

    本文出自   http://blog.csdn.net/shuangde800 题目链接: 点击打开链接 题目大意 给定一棵树,选择尽量少的节点,使得每个没有选中的结点至少和一个已选结点相邻. 思路 ...

  2. uva 1292 树形dp

    UVA 1292 - Strategic game 守卫城市,城市由n个点和n-1条边组成的树,要求在点上安排士兵,守卫与点相连的边.问最少要安排多少士兵. 典型的树形dp.每一个点有两个状态: dp ...

  3. UVA 1292 十二 Strategic game

    Strategic game Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Sta ...

  4. POJ1463:Strategic game(树形DP)

    Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot f ...

  5. Strategic game(POJ 1463 树形DP)

    Strategic game Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 7490   Accepted: 3483 De ...

  6. HDU 1054 Strategic Game(树形DP)

    Problem Description Bob enjoys playing computer games, especially strategic games, but sometimes he ...

  7. UVa 10859 - Placing Lampposts 树形DP 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  8. poj1463 Strategic game【树形DP】

    Strategic game Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 9582   Accepted: 4516 De ...

  9. UVA - 1218 Perfect Service(树形dp)

    题目链接:id=36043">UVA - 1218 Perfect Service 题意 有n台电脑.互相以无根树的方式连接,现要将当中一部分电脑作为server,且要求每台电脑必须连 ...

随机推荐

  1. POJ3352-Road Construction(边连通分量)

    It's almost summer time, and that means that it's almost summer construction time! This year, the go ...

  2. 跨域请求Ajax(POST)处理方法

    getXSSAjax(function() {  //跨域请求        that.ajaxDara(self);}, (bs_tita.webapi || "http://webapi ...

  3. UVA 1995 I can guess the structer

    模 拟 /*by SilverN*/ #include<algorithm> #include<iostream> #include<cstring> #inclu ...

  4. Memory Ordering in Modern Microprocessors

    Linux has supported a large number of SMP systems based on a variety of CPUs since the 2.0 kernel. L ...

  5. Delphi简单的数据操作类

    unit MyClass; uses   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,   VCL ...

  6. git一个本地仓库连接多个远程仓库

    前言:由于公司的GIT是内网服务器,而在家工作访问不了内网服务器,由此想把本地仓库连接一个外网的GIT服务器(码云),方便不在公司时开发. 原文 某些场合,一个git项目需要能同时使用两个甚至多个远程 ...

  7. 洛谷——P3379 【模板】最近公共祖先(LCA)

    P3379 [模板]最近公共祖先(LCA) 题目描述 如题,给定一棵有根多叉树,请求出指定两个点直接最近的公共祖先. 输入输出格式 输入格式: 第一行包含三个正整数N.M.S,分别表示树的结点个数.询 ...

  8. 高数(A)下 第十一章

    11.1 11.2 11.3 11.4 11.5

  9. ASPNET Core 部署 Linux — 使用 Jexus Web Server

    第一步 安装.Net Core环境 安装 dotnet 环境参见官方网站 https://www.microsoft.com/net/core. 选择对应的系统版本进行安装.安装完成过后 输入命令查看 ...

  10. HDU 2054 A == B ?(找小数点)

    题目链接:pid=2054" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=2054 Prob ...