题目链接

依旧是树形dp啦,一样的找根节点然后自下而上更新即可

设\(dp_{i,0}\)表示第i个不设,\(dp_{i,1}\)表示第i个设一个,容易得到其状态转移

\(dp_{i,0} = \sum{dp_{j,1}}(j为i的儿子节点)\)

\(dp_{i,1} = 1 + \sum{min(dp_{j,0}, dp_{j,1})}(j为i的儿子节点)\)

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std; const int maxn = 1507;
vector<int> son[maxn];
int in[maxn], dp[maxn][2]; void dfs(int fa) {
dp[fa][0] = 0;
dp[fa][1] = 1;
for(int i = 0; i < son[fa].size(); ++i) {
int v = son[fa][i];
dfs(v);
dp[fa][1] += min(dp[v][0], dp[v][1]);
dp[fa][0] += dp[v][1];
}
} void run_case() {
int n;
while(cin >> n) {
memset(dp, 0, sizeof(dp)), memset(in, 0, sizeof(in));
for(int i = 0; i < n; ++i) {
int fa, num;
scanf("%d:(%d)", &fa, &num);
son[fa].clear();
for(int j = 0; j < num; ++j) {
int v;
scanf("%d", &v);
in[v]++;
son[fa].push_back(v);
}
}
for(int i = 0; i < n; ++i)
if(!in[i]) {
dfs(i);
cout << min(dp[i][0], dp[i][1]) << "\n";
break;
}
} } int main() {
//ios::sync_with_stdio(false), cout.tie(0);
cout.flags(ios::fixed);cout.precision(10);
run_case();
//cout.flush();
return 0;
}

Strategic game POJ - 1463的更多相关文章

  1. 树形dp compare E - Cell Phone Network POJ - 3659 B - Strategic game POJ - 1463

    B - Strategic game POJ - 1463   题目大意:给你一棵树,让你放最少的东西来覆盖所有的边   这个题目之前写过,就是一个简单的树形dp的板题,因为这个每一个节点都需要挺好处 ...

  2. Strategic game(POJ 1463 树形DP)

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

  3. Strategic game POJ - 1463 【最小点覆盖集】

    Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solu ...

  4. (树形DP)Strategic game POJ - 1463

    题意: 给你一棵树,树的每一个节点可以守护与其相连的所有边,问你最少用多少个节点可以守护这整棵树 思路: 仔细思考不难发现,要想守护一条边,边的两个端点必须有一个可以被选(两个都选也可以),然后这个问 ...

  5. Strategic game POJ - 1463 dfs

    题意+题解: 1 //5 2 //1 1 3 //2 1 4 //3 1 5 //1 1 6 //给你5个点,从下面第二行到第五行(称为i行),每一行两个数x,y.表示i和x之间有一条边.这一条边的长 ...

  6. Strategic game POJ - 1463 树型dp

    //题意:就是你需要派最少的士兵来巡查每一条边.相当于求最少点覆盖,用最少的点将所有边都覆盖掉//题解://因为这是一棵树,所以对于每一条边的两个端点,肯定要至少有一个点需要放入士兵,那么对于x-&g ...

  7. poj 1463 Strategic game DP

    题目地址:http://poj.org/problem?id=1463 题目: Strategic game Time Limit: 2000MS   Memory Limit: 10000K Tot ...

  8. poj 1463 Strategic game

    题目链接:http://poj.org/problem?id=1463 题意:给出一个无向图,每个节点只有一个父亲节点,可以有多个孩子节点,在一个节点上如果有一位战士守着,那么他可以守住和此节点相连的 ...

  9. POJ 1463 Strategic game(二分图最大匹配)

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

随机推荐

  1. AcWing 125. 耍杂技的牛

    //按照wi+si从小到大的顺序排,结果一定最优,最大的危险系数一定是最小的 //类比于国王游戏 #include <iostream> #include <algorithm> ...

  2. find & grep 总 结

    前言 关于本文 总 结 了 find.grep常 规 用 法,正 则 表 达 式,find与 grep合 用 以 及 自 定 义 搜 索 函 数 等 什么是find和grep find 和 grep ...

  3. Educational Codeforces Round 82 (Rated for Div. 2)D(模拟)

    从低位到高位枚举,当前位没有就去高位找到有的将其一步步拆分,当前位多余的合并到更高一位 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h&g ...

  4. GO111MODULE

    GO111MODULE的功能: //为了解决项目不用放在go的src目录下,src应该放一些官方的包,而不应该放项目 //模块是相关Go包的集合.modules是源代码交换和版本控制的单元. go命令 ...

  5. zabbix4.2安装配置指南

    [声名]本实例中采用Linux CentOS 7系统 CentOS Linux release 7.6.1810 (Core) 1.安装LAMP环境: [root@localhost /]# yum ...

  6. linux虚拟机安装jenkins及maven/jdk配置

    一.jenkins安装 (1)tomcat下载,下载地址:https://tomcat.apache.org 选择对应的版本,以下以新版的tomcat 9.0版本为例 下载zip包 (2)jenkin ...

  7. 【一句话解释】docker and vm

    效果 在一个host上面运行多个os,达到快速部署以及充分利用资源的额目的 vm 虚拟机,会模拟一个完整的操作系统堆栈出来. 缺点开销大,优点,guest os 是一个完整的操作系统 根据hyperv ...

  8. PyCharm中的django项目的引入

    1.从github或者从本地的文件打开项目 2.项目引入后,python manage.py runserver 8080启动 1.启动的时候有错误,看看要引入的模块错误,然后把模块引入 D:\.St ...

  9. Windows Server 2012 忘记登录密码怎么办?

    Windows Server 2012系统 忘记登录密码处理方法,此方法在其他 Server 系统应该是通用的(其他系统未做测试,请知悉) 电脑 Windows Server 2012系统 做好的U盘 ...

  10. Swiper 移动端全屏轮播图效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...