ACM: 动态规划题 poj 3659
来源:互联网 发布:金山tw域名遭抢注 编辑:程序博客网 时间:2024/06/03 20:12
Farmer John has decided to give each of his cows a cell phone inhopes to encourage their social interaction. This, however,requires him to set up cell phone towers on his N (1 ≤N ≤ 10,000) pastures (conveniently numbered 1..N) sothey can all communicate.
Exactly N-1 pairs of pastures are adjacent, and for anytwo pastures A and B (1 ≤ A ≤ N; 1 ≤B ≤ N; A ≠ B) there is a sequence ofadjacent pastures such that A is the first pasture in thesequence and B is the last. Farmer John can only place cellphone towers in the pastures, and each tower has enough range toprovide service to the pasture it is on and all pastures adjacentto the pasture with the cell tower.
Help him determine the minimum number of towers he must installto provide cell phone service to each pasture.
Input
* Line 1: A single integer: N
* Lines 2..N: Each line specifies a pair of adjacentpastures with two space-separated integers: A andB
Output
* Line 1: A single integer indicating the minimum number oftowers to install
Sample Input
5
1 3
5 2
4 3
3 5
Sample Output
2
题意: 一棵树种, 每个节点可以覆盖相邻的节点, 用最少的节点覆盖整棵树.
解题思路:
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define MAX 20005
const int INF = (1<<29);
struct node
{
}edges[MAX];
int n;
int first[MAX], num, d[MAX];
int dp[MAX][3];
bool vis[MAX];
inline int min(int a, int b)
{
}
inline void add(int u, int v)
{
}
void read_graph()
{
}
void dfs(int u)
{
}
int main()
{
//
}
- ACM: 动态规划题 poj 3659
- ACM: 简单动态规划题 poj 2955
- ACM: 动态规划题 poj 2241
- ACM: 动态规划题 poj 1054
- ACM: 动态规划题 poj 2948
- ACM: 动态规划题 poj 1925
- ACM: 动态规划题 poj 3034
- ACM: 动态规划题 poj 2411
- ACM: 动态规划题 poj 1947
- ACM: 动态规划题 poj 2486
- ACM: 动态规划题 poj 3140
- ACM: 动态规划题 poj 2923
- ACM: dp动态规划题(难) poj 3267 …
- ACM: dp题(动态规划) poj 2151 (d…
- ACM: 树状DP 动态规划题 poj 1463 …
- ACM: 动态规划题 poj 2057 树状DP
- ACM:动态规划题 poj 1015
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 1947
- ACM: 动态规划题 poj 2486
- ACM: 动态规划题 poj 3140
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 1192 树形DP
- ACM: 动态规划题 poj 3659
- 动态规划: 经典0-1背包问题 (转)
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 3211 背包变…
- (OK)(OK) Fedora23——NS3(MANETs)——Docker(busybox)——genymotion(android)——All is OK
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 3093 0-1背包
- ACM: 动态规划题 poj&nb…
- ACM: 动态规划题 poj 2923