POJ1463Strategic game题解动态规划DP

Strategic game(树形dp) 题目:POJ 1463 Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem... 阅读详情
Strategic game
Time Limit: 2000MS Memory Limit: 10000K
Total Submissions: 2096 Accepted: 870

Description

Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which form a tree. He has to put the minimum number of soldiers on the nodes so that they can observe all the edges. Can you help him?

Your program should find the minimum number of soldiers that Bob has to put for a given tree.

For example for the tree:

the solution is one soldier ( at the node 1).

Input

The input contains several data sets in text format. Each data set represents a tree with the following description:

  • the number of nodes
  • the description of each node in the following format
    node_identifier:(number_of_roads) node_identifier1 node_identifier2 ... node_identifiernumber_of_roads
    or
    node_identifier:(0)

The node identifiers are integer numbers between 0 and n-1, for n nodes (0 < n <= 1500);the number_of_roads in each line of input will no more than 10. Every edge appears only once in the input data.

Output

The output should be printed on the standard output. For each given input data set, print one integer number in a single line that gives the result (the minimum number of soldiers). An example is given in the following:

Sample Input

4
0:(1) 1
1:(2) 2 3
2:(0)
3:(0)
5
3:(3) 1 4 2
1:(1) 0
2:(0)
0:(0)
4:(0)

Sample Output

1
2

Source

入门树状DP
题目描述了一个树形结构,在结点上可安放0个或1个士兵,
要求在满足每条边的两端至少有一个士兵的条件下求得士兵最少数
深度优先搜索遍历树的每一个节点,对于一个节点u,存在两种状态,
以1表示放置,0表示不放置,
d[u][1]表示节点u放置士兵情况下以u为节点子树的最优值,
同理d[u][0]表示不放置为最优值,
转移方程为:
for(v 属于 u的子节点) d[u][1] += max(d[v][0], d[v][1])
for(v 属于 u的子节点) d[u][0] += d[v][1]
最后结果为根节点放置和不放置情况中的最优值
【WRF-Urban运行】WRF-SLUCM耦合建模参数设置及模拟运行 WRF-SLUCM耦合建模参数设置及模拟运行 阅读详情

相关推荐

【自动驾驶学习笔记——Prescan和Simulink 学习笔记和问题记录(1)】

主要记录一些Prescan/Simulink 联合仿真出现的问题。

ly1336545868的博客 1465

POJ - 1463 Strategic game (树状动态规划)

这题做的心塞。。。 整个思路非常清晰,d[i][0]表示第i个结点不设置监察的情况下至少需要的数量;d[i][1]表示第i个结点设置检查的情况下的最小需要的数量。 状态转移方程见代码。 但是万万没想到的是,在实现过程中修改了4遍代码,wa了若干次才AC。。。。 下面来总结一下各种wa代码: 版本1:开二维数组存储树(本质上是邻接矩阵存储,把树存储成图),报错TLE。这时候第一感觉是每次更...

weixin_30399055的博客 163

基于Spring Boot框架的网上蛋糕销售系统

随着互联网的普及和电子商务的迅猛发展,网上购物已经成为人们日常生活的一部分。蛋糕作为一种受欢迎的食品,其销售市场也逐渐向网络化方向发展。网上蛋糕销售系统能够打破时间和地域的限制,让消费者随时随地浏览和购买蛋糕,同时也为蛋糕商家提供了一个展示和销售产品的平台。该系统的开发旨在提高蛋糕预定和销售的便捷性,节约时间和经济成本,并推动蛋糕市场的进一步发展。开发语言:Java,一种面向对象的编程语言,具有跨平台性、稳定性和安全性等特点,适用于构建大型、复杂的Web应用程序。 框架:Spring Boot,一个基于Sp

2301_81127431的博客 996

POJ 1463 :Strategic game 树形动规

`Time Limit: 2000MS Memory Limit: 10000KDescriptionBob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now

pku_Coder的博客 487

Python | 处理CMIP6 NC数据,以tas为例

各位同学,一般在文章最后一章我们可能会做不同气候情景下变量的未来时空变化特征,类似上图。从cmip6下载的nc数据常需要转换格式、裁剪到研究区和重采样等,本期代码可以解决这类问题。

qq_48539301的博客 1384

手把手讲解RTX5操作系统在GD32F407上的移植

然后将GD32F4xx_Demo_Suites_V2.6.4\GD32407V_START_Demo_Suites\Projects\01_GPIO_Running_LED下面的main函数复制到我们的项目文件夹中;打开对应GD32407V_START_Demo_Suites的文件夹下面的Utilities,复制gd32f407v_start.c和gd32f407v_start.h文件到一开始项目保存的文件夹下面;为了验证我们的操作系统是否被正确添加,是否能够正确运行,我们需要添加示例文件;

Praguejing的博客 1860

hdu 1054 Strategic Game(KM算法求最大匹配数)

** hdu 1054 Strategic Game ** 若有错误,烦请指出,不胜感激 Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. N...

逝者如斯夫,不舍昼夜 221

Windows 10 下 DockerToolbox 安装全攻略:从下载到配置阿里云镜像加速

本文详细介绍了在Windows 10系统上安装和配置DockerToolbox的完整流程。从下载安装包、执行初步安装,到关键步骤——修改虚拟机存储路径以及配置阿里云镜像加速器,旨在帮助开发者,尤其是初次接触Docker的新手,快速搭建高效的本地容器开发环境,并解决国内镜像下载缓慢的痛点。

moon9的博客 476

动态规划C语言初学

动态规划问题解决的基本思想: 1、根绝问题所求的那一项和变量的个数,确定是一维数组,二维数组或者多维数组。 2、写出初始值,一般是某个变量为1或者0 的特殊情况时候的解。 3、通过循环,一般是两个循环中间每一层循环表示一个变量的递增情况。 4、在循环中间写出对应的递推关系表达式,求出问题的每一项。 5、根据题意得到答案,一般是数组的最后一项。 提示 : 找递推关系是动态规划最难的一步,

weisian的博客 3万+

halcon算子翻译——connection

算子:connection(Region : ConnectedRegions : : ) 功能:分离一个区域中相连接的部分(变成多个区域)。 输入参数: Region:输入一个区域; 输出参数: ConnectedRegions: ———————————————— 版权声明:本文为优快云博主「机器人自动化控制」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.youkuaiyun.com/haier123888/article/details/1

haier123888的博客 4828

FFmpeg 开发(14):Android FFmpeg + MediaCodec 实现视频硬解码

MediaCodec 是 Android 提供的用于对音视频进行编解码的类,它通过访问底层的 codec 来实现编解码的功能,是 Android media 基础框架的一部分,通常和 MediaExtractor, MediaSync, MediaMuxer, MediaCrypto, MediaDrm, Image, Surface和AudioTrack 一起使用。

字节流动 3万+

POJ-1463 Strategic game 树形dp

POJ-1463 Strategic game 树形dp 题目 Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the...

weixin_44273380的博客 179

台球 PCOL:极致物理还原的网页斯诺克引擎(附源码深度解析)

*完整源码地址**:[https://github.com/billiards/pcol-core](https://github.com/billiards/pcol-core)(包含详细文档与示例)通过这个项目,我们不仅创建了一个游戏,更构建了一个**可扩展的物理引擎框架**,为网页端复杂物理模拟开辟了新的可能性。**在线体验**:[https://pcol.billiards](https://pcol.billiards)(支持移动端触控操作)clone.velocity.x *= -0.92;

Loving_enjoy的博客 2797

Strategic game POJ - 1463 树形DP

题目链接:POJ - 1463 题目大意:给你一个无向图,然后每个点都会被标记的点直接相邻,并切被标记的点大于等于1的前提下,最少需要对几个点进行染色。 具体思路: dp[i][0] 代表标号为I的点在不染色的前提下,这个点代表的子树符合条件最少需要对这个点的几个点进行染色。 dp[i][1] 代表标号为i的点在染色的前提下,这个点代表的子树符合条件最少需要对这个点的子树中的几...

diaomeijiao3430的博客 156

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Poj 1463 Strategic game 【树形DP】

http://poj.org/problem?id=1463 题目大意:有若干节点,节点之间有路相连,构成树形结构,如果在一个节点上放置一个士兵,与这个节点相连的路就可以被监视,现在要监视所有的路,问至少要多少士兵。 最优解结构:dp[i][0],dp[i][1]分别表示不在i节点上和在i节点上放置士兵时整个以i节点为根的子树被覆盖用到的最少士兵数目。 状态转移方程: 对叶子...

bantengbang8949的博客 117

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

POJ - 1463Strategic game入门树形DP

POJ - 1463 Strategic game Time Limit: 2000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Submit Status Description Bob enjoys playing computer games, es

qq_18661257的专栏 791

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

poj 1463 Strategic game

http://poj.org/problem?id=1463 有两种做法,一种是二分图,一种是树形DP,这里两种都做了。 二分图的。 就是经典的二分图最小点覆盖,要选取最小的点,使得所有的边与这些点关联,(可以一条边关联两个点,为了需要哟) 那么我们建的是无向边,因为可以互相关联,还是利用经典的拆点思想, 本来要若原图中i与j有边。我们要连的是i到j+n,j到i+n,但这样连的...

121

[POJ 1463] Strategic Game

[题目链接] http://poj.org/problem?id=1463 [算法] 树形DP [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #incl...

88

POJ1463 Strategic game

POJ1463 题 意:给定一个树,求一个最少的节点集合,以至于每一条至少有一个节点在这个在这个集合中。 数据范围: 0 &lt; n &lt;= 1500 输入样例: 4 0:(1) 1 //0代表父节点 //括号里面的1 代表子节点的个数 之后就是子节点编号 1:(2) 2 3 2:(0) 3:(0) 5 3:(3) 1 4 2 1:(1) 0 2:(0) 0:(0) ...

子灬丶逾 325

poj 1463 Strategic game(树形dp)

poj 1463 Strategic game

PKU_ZZY的博客 762

POJ1463 Strategic game 树形dp

http://poj.org/problem?id=1463 Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following p...

永夜莫明的博客 214

POJ 1463 Strategic game

题目大意: 注释代码: 无注释代码

源代码 607

【dp每一天】POJ - 1463 Strategic game (树形dp)

POJ - 1463 题意: 全部边覆盖,所加的士兵的最小值,递推式可直接看代码。说起来边覆盖感觉好像。。二分图? #include #include #include #include using namespace std; const int maxn = 1600; struct node { int to,next; node(){} node(in

shinimashzi 232

POJ-1463-Strategic game(树形dp)

点击这里一起去POJ玩游戏 Strategic game Time Limit:2000MS Memory Limit:10000K Total Submissions:11235 Accepted:5254 Description Bob enjoys playing computer games, especially strategic ...

From now on...的Blogs 331

POJ 1463——Strategic game

Strategic game Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 4045   Accepted: 1824 Description Bob enjoys playing computer games, especially strategic games,

蛤蛤~ 870

POJ1463 Strategic game(树形DP)

传送门 http://poj.org/problem?id=1463 这是一道树形DP入门题。 分析符号说明 node_num:结点数 edge_num:边数 saved_edge_num:无向图中存储的边的数量 dp[][]:动态规划数组dp[i][j]表示第i的结点是(j=1)否(j=0)有兵的情况下其与子结点的所需兵的最小值 x:父结点 y:子结点 分析 由题目中t...

空空的池子 225
上一篇: POJ1404I-Keyboard题解动态规划DP
下一篇: POJ2192Zipper动态规划DP
power721
博客等级 码龄18年 176粉丝 135原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值