题目链接

依旧是树形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. python之文件复制

    python文件复制操作. # -*- coding: utf-8 -*- import shutil import os # file_path = 'C:\\Users\\WT\\Desktop\ ...

  2. CentOS 7下用firewall-cmd控制端口与端口转发

    # 将80端口的流量转发至192.168.0.1的8080端口 1.firewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toad ...

  3. Nearest Interesting Number

    Polycarp knows that if the sum of the digits of a number is divisible by 33, then the number itself ...

  4. FFmpeg—— Bitstream Filters 作用

    原文链接: https://stackoverflow.com/questions/32028437/what-are-bitstream-filters-in-ffmpeg Let me expla ...

  5. jquery--获取input checkbox是否被选中以及渲染checkbox选中状态

    jquery获取checkbox是否被选中 html <div><input type="checkbox" id="is_delete" n ...

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

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

  7. DVWA全级别之Brute Force(暴力破解)

    Brute Force Brute Force,即暴力(破解),是指黑客利用密码字典,使用穷举法猜解出用户口令. 首先我们登录DVWA(admin,password),之后我们看网络是否为无代理,: ...

  8. mysql 数据库中的模式替换

    1, REPLACE 使用 -UPDATE tbl_name SET field_name = REPLACE(field_name,old_str,new_str) WHERE conditions ...

  9. vue简单计数器

    //App.vue <template> <div id="app"> <!-- <img src="./assets/logo.pn ...

  10. 前端——语言——Core JS——《The good part》读书笔记——第三章节(Object)

    本章介绍对象. 在学习Java时,对象理解为公共事物的抽象,实例为具体的个例,对象为抽象的概念,例如人为抽象的概念,具体的个例为张三,李四. Java对象种类多,包含普通类,JavaBean,注解,枚 ...