poj 1463 Strategic game DP
题目地址:http://poj.org/problem?id=1463
题目:
| Time Limit: 2000MS | Memory Limit: 10000K | |
| Total Submissions: 7929 | Accepted: 3692 |
Description
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 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
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
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime> #define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
#define PI acos((double)-1)
#define E exp(double(1))
const int K=+;
short vis[K],head[K],cnt;
struct Edge
{
short next,to;
}edge[K*];
void add(int u,int v)
{
edge[cnt].next=head[u];
edge[cnt].to=v;
head[u]=cnt++;
}
void dfs(int x,int &v1,int &v2)
{
v1=;v2=;
vis[x]=;
int x1,x2;
for(int i=head[x];~i;i=edge[i].next)
{
int v=edge[i].to;
if(vis[v])continue;
dfs(v,x1,x2);
v1+=min(x1,x2);
v2+=x1;
}
}
int main(void)
{
int n;
while(~scanf("%d",&n))
{
cnt=;
memset(head,-,sizeof(head));
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
{
int u,v,k;
scanf("%d:(%d)",&u,&k);
while(k--)
scanf("%d",&v),add(u,v),add(v,u);
}
int x,y;
dfs(,x,y);
printf("%d\n",min(x,y));
}
return ;
}
poj 1463 Strategic game DP的更多相关文章
- POJ 1463 Strategic game(树形DP入门)
题意: 给定一棵树, 问最少要占据多少个点才能守护所有边 分析: 树形DP枚举每个点放与不放 树形DP: #include<cstdio> #include<iostream> ...
- Strategic game POJ - 1463 树型dp
//题意:就是你需要派最少的士兵来巡查每一条边.相当于求最少点覆盖,用最少的点将所有边都覆盖掉//题解://因为这是一棵树,所以对于每一条边的两个端点,肯定要至少有一个点需要放入士兵,那么对于x-&g ...
- poj 1463 Strategic game
题目链接:http://poj.org/problem?id=1463 题意:给出一个无向图,每个节点只有一个父亲节点,可以有多个孩子节点,在一个节点上如果有一位战士守着,那么他可以守住和此节点相连的 ...
- POJ 1463 Strategic game(二分图最大匹配)
Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot f ...
- POJ - 1463 Strategic game (树状动态规划)
这题做的心塞... 整个思路非常清晰,d[i][0]表示第i个结点不设置监察的情况下至少需要的数量:d[i][1]表示第i个结点设置检查的情况下的最小需要的数量. 状态转移方程见代码. 但是万万没想到 ...
- 树形dp compare E - Cell Phone Network POJ - 3659 B - Strategic game POJ - 1463
B - Strategic game POJ - 1463 题目大意:给你一棵树,让你放最少的东西来覆盖所有的边 这个题目之前写过,就是一个简单的树形dp的板题,因为这个每一个节点都需要挺好处 ...
- POJ.3624 Charm Bracelet(DP 01背包)
POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...
- POJ 2995 Brackets 区间DP
POJ 2995 Brackets 区间DP 题意 大意:给你一个字符串,询问这个字符串满足要求的有多少,()和[]都是一个匹配.需要注意的是这里的匹配规则. 解题思路 区间DP,开始自己没想到是区间 ...
- Strategic game(POJ 1463 树形DP)
Strategic game Time Limit: 2000MS Memory Limit: 10000K Total Submissions: 7490 Accepted: 3483 De ...
随机推荐
- Android 手机卫士15--程序锁
1.基本思路 ①.创建已加锁应用的数据库(字段:_id,packagename),如果应用已加锁,将加锁应用的包名维护到数据库中 ②.已加锁+未加锁 == 手机中所有应用(AppInfoProvide ...
- nodejs连接mysql并进行简单的增删查改
最近在入门nodejs,正好学习到了如何使用nodejs进行数据库的连接,觉得比较重要,便写一下随笔,简单地记录一下 使用在安装好node之后,我们可以使用npm命令,在项目的根目录,安装nodejs ...
- mybatis hellworld
用maven来进行搭建项目的~~ 1. 搭建环境 pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" x ...
- Vue方法与事件
gitHub地址:https://github.com/lily1010/vue_learn/tree/master/lesson10 一 vue方法实现 <!DOCTYPE html> ...
- RHEL7文件归档与压缩
本文介绍RHEL7.2文件的归档和压缩 文件归档 归档的好处:方便使用.查询.阅读,易于管理 (批量删除文件) 常用操作 命令:tar 作用:将许多文件一起保存至一个单独的磁带或磁盘归档,并能从归档中 ...
- compass制作sprite雪碧图
1.安装compass.(需要先安装ruby) 命令行:gem install compass 2.新建一个compass 项目 命令行:compass create myproject 3.在myp ...
- ArcGIS Add-in——自动保存编辑
需求:由于初次使用ArcGIS编辑器不习惯.数据量大造成经常程序未响应.计算机断电等因素,造成编辑的数据没有保存,影响了生产效率,本人根据草色静然的博文,总结了自动保存编辑的实现方法. 分析:自动保存 ...
- 创建第一个Android 5.0应用程序
1.新建一个Andriod项目,并配置相关参数 2.接着下一步 3.接着下一步,配置相关参数 4.完成后出现下面界面 5.运行此项目 6.你可以在菜单中看到刚才新建的Helloworld app图标
- Masonry第三方代码约束
#import "RootViewController.h" #import "Masonry.h" @interface RootViewController ...
- C++语言-04-重载
相关概念 重载 在同一作用域中为某个函数和运算符指定多个定义,分别成为函数重载和运算符重载 重载声明 与之前已经在作用域内声明过的函数或方法具有相同名称的声明,参数列表和定义不同 重载决策 调用一个重 ...