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 ...
随机推荐
- php中设定一个全局异常处理。全局catch。默认catch。默认异常处理
<?php function handleMissedException($e) { echo "Sorry, something is wrong. Please try again ...
- 用C语言制作爱心
国庆我们实验室布置了作业,其中一项为,利用流程控制语句打印以下图形 * *** ***** ******* ***** *** * 代码如下 #include <stdio.h> int ...
- postgresql 9.6 rc1发布
postgresql 9.6 rc1发布了,意味着postgresql 9.6正式版将会越来越近了. 对于dss来说,postgresql远优于mysql,尤其是9.6新引入的并行执行,将大大提高性能 ...
- Socket 学习实例
整理一份Socket代码,整理前辈的代码 http://www.cnblogs.com/yellowapplemylove/archive/2011/04/19/2021586.html 直接贴代码 ...
- 区别CALL SCREEN/SET SCREEN/LEAVE TO SCREEN
分类: 1,CALL SCREEN XXXX将在Screen调用栈(CALL STACK)上面添加一层调用(进栈),调用XXXX的PBO和PAI,如果XXXX的Next Screen不为0,那么将继续 ...
- ExtJs中xtype与组件类的对应表
from:http://blog.163.com/jx_dream/blog/static/117056627201223091021410/ 核心提示:我们在使用 ExtJs 创建组件时最容易理解的 ...
- English Training Material - 03
Cross-cultural understanding (2) 1 The following text is about cultural diversity. Read it through o ...
- Sharepoint学习笔记—习题系列--70-573习题解析 -(Q94-Q96)
Question 94You need to create a custom application that provides users with the ability to create a ...
- LayoutTransition实现显示、隐藏动画
public class Main4Activity extends Activity { private TextView tv1; private Button button1; private ...
- tableview直接滚动至最后一行的问题
tableview直接滚动至最后一行 类似聊天界面,tableview应该直接显示在最后一行,并且不应该有滚动的出现. 在网上查了很久,直接滚动至最后一行很容易实现,有两种方法比较好. 1. 调用sc ...