树形DP UVA 1292 Strategic game
/*
题解:选择一个点,它相邻的点都当做被选择,问最少选择多少点将所有点都被选择
树形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的更多相关文章
- UVa 1292 - Strategic game (树形dp)
本文出自 http://blog.csdn.net/shuangde800 题目链接: 点击打开链接 题目大意 给定一棵树,选择尽量少的节点,使得每个没有选中的结点至少和一个已选结点相邻. 思路 ...
- uva 1292 树形dp
UVA 1292 - Strategic game 守卫城市,城市由n个点和n-1条边组成的树,要求在点上安排士兵,守卫与点相连的边.问最少要安排多少士兵. 典型的树形dp.每一个点有两个状态: dp ...
- UVA 1292 十二 Strategic game
Strategic game Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Sta ...
- POJ1463:Strategic game(树形DP)
Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot f ...
- Strategic game(POJ 1463 树形DP)
Strategic game Time Limit: 2000MS Memory Limit: 10000K Total Submissions: 7490 Accepted: 3483 De ...
- HDU 1054 Strategic Game(树形DP)
Problem Description Bob enjoys playing computer games, especially strategic games, but sometimes he ...
- UVa 10859 - Placing Lampposts 树形DP 难度: 2
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- poj1463 Strategic game【树形DP】
Strategic game Time Limit: 2000MS Memory Limit: 10000K Total Submissions: 9582 Accepted: 4516 De ...
- UVA - 1218 Perfect Service(树形dp)
题目链接:id=36043">UVA - 1218 Perfect Service 题意 有n台电脑.互相以无根树的方式连接,现要将当中一部分电脑作为server,且要求每台电脑必须连 ...
随机推荐
- bzoj 4991 [Usaco2017 Feb]Why Did the Cow Cross the Road III(cdq分治,树状数组)
题目描述 Farmer John is continuing to ponder the issue of cows crossing the road through his farm, intro ...
- 【ZJOI2017 Round1练习&BZOJ4774】D3T2 road(斯坦纳树,状压DP)
题意: 对于边带权的无向图 G = (V, E),请选择一些边, 使得1<=i<=d,i号节点和 n − i + 1 号节点可以通过选中的边连通, 最小化选中的所有边的权值和. d< ...
- Codeforces713D. Animals and Puzzle
$n<=1000,m<=1000$,$n*m$的01矩阵,给$t<=1000000$个询问,每次问一个矩形中最大的1正方形的边长. 先想想不考虑“一个矩形中”的限制,那记$f(i,j ...
- springMVC @Value的使用
@Value 功能:将一个SpEL(SpEL:spring表达式类似于ognl)表达式结果映射到功能处理方法的参数上 例子:获取系统参数'java.vm.version'的值给到变量jvmVersio ...
- 使用XML定义组件样式
<TextView android:layout_width="match_parent" android:layout_height="wrap_content& ...
- javabean组件
javaBean组件引入: javaBean是使用java语言开发的一个可重用的组件,在Jsp开发中可以使用javaBean减少重复代码,使整个JSP代码的开发更简洁. 我们首先创建一个类叫做Stud ...
- 【转载】Spring Boot【快速入门】2019.05.19
原文出处:https://www.cnblogs.com/wmyskxz/p/9010832.html Spring Boot 概述 Build Anything with Spring Boot ...
- openstack setup demo Compute service
本文包含以下部分 Compute service overview Install and configure controller node Prerequisites Install and co ...
- CSS3的animation功能
旋转动画 <img src="https://facebook.github.io/react/img/logo.svg" class="App-logo" ...
- 使用go语言实现简单的反向代理工具激活IntelliJ和PyCharm,持续更新
最近Jetbrians系列IDE更新至2017.3版本,激活检测机制也变成了动态封禁域名,导致大部分域名激活被屏蔽了,所以找了下资料,根据ilanyu的代码,改了下地址,实现了本地反向代理激活服务器. ...