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 ...
随机推荐
- 转载 教你使用PS来制作unity3D随机地形
- nginx服务器是怎么执行php脚本的?
简单的说: fastCGI是nginx和php之间的一个通信接口,该接口实际处理过程通过启动php-fpm进程来解 析php脚本,即php-fpm相 当于一个动态应用服务器,从而实现nginx动态解析 ...
- 高效构建Web应用 教你玩转Play框架 http://www.anool.net/?p=577
Play 框架是一个完整的Web应用开发框架,覆盖了Web应用开发的各个方面.Play 框架在设计的时候借鉴了流行的 Ruby on Rails 和 Grails 等框架,又有自己独有的优势.使用 P ...
- Android文件操作
将数据写入Internal Storage: String fileName = "myfile.txt"; String str="保存数据到内部存储"; t ...
- Android 开发组件
每一个应用程序都有自己独立的运行沙盒(授予应用程序代码的访问权) Android操作系统是一个多用户的Linux系统,其中的每一个应用程序都是一个独立的用户. 系统会为每一个应用程序分配一个唯一的Li ...
- BI笔记-SSAS部署的几种方式及部署后的SSAS刷新
SSAS的部署方式在哥本哈士奇的博客:BI笔记之--- SSAS部署的几种方式已经介绍了四种方式,在这里再介绍一种比较常用的快速部署方式. 环境约定:SQL Server 2008 R2 示例库:Ad ...
- Spring-2-J Goblin Wars(SPOJ AMR11J)解题报告及测试数据
Goblin Wars Time Limit:432MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Th ...
- mongodb--java操作
一.mongodb客户端 mongodb提供诸多语言的客户端,也包括java的客户端.通过这些客户端,我们可以很方便地使用编写代码的方式对mongodb进行操作.这里使用java客户端进行示例.使用j ...
- PL/SQL之--函数
一.函数 函数是作为数据库对象存储在oracle数据库中,函数又被称为PL/SQL子程序.oracle处理使用系统提供的函数之外,用户还可以自己定义函数.函数通常被作为一个表达式来调用或存储过程的一个 ...
- 更改ubuntu下mysql的密码
1.首先,进入环境中去,即 mysql -u root -p ,然后输入原始密码 2.此时会出现 mysql > 3.开始修改密码: mysql > use mysql ; ...