ACM: 动态规划题 bnu 13149
来源:互联网 发布:服务器端语言编程 编辑:程序博客网 时间:2024/06/10 07:36
Placing Lampposts
Description
As a part of the mission 'Beautification of Dhaka City', thegovernment has decided to replace all the old lampposts with newexpensive ones. Since the new ones are quite expensive and thebudget is not up to the requirement, the government has decided tobuy the minimum number of lampposts required to light the wholecity.
Dhaka city can be modeled as an undirected graph with no cycles,multi-edges or loops. There are several roads and junctions. Alamppost can only be placed on junctions. These lampposts can emitlight in all the directions and that means a lamppost that isplaced in a junction will light all the roads leading away fromit.
The 'Dhaka City Corporation' has given you the road map of Dhakacity. You are hired to find the minimum number of lampposts thatwill be required to light the whole city. These lampposts can thenbe placed on the required junctions to provide the service. Therecould be many combinations of placing these lampposts that willstill cover all the roads. In that case, you have to place them insuch a way so that the number of roads receiving light from twolampposts is maximized. (A careful thought will reveal that all theroads will get light either from one post or two posts).
Input
Input starts with an integer T (≤ 30), denotingthe number of test cases.
Each case starts with a blank line. The next line contains twointegers N (1 ≤ N ≤ 1000) and M (0 ≤ M <N) which indicate the number of junctions and roadsrespectively. The junctions are numbered from 0 toN-1. Each of the next M lines contains two integersa and b (0 ≤ a, b < N, a ≠ b), whichdenotes that there is a road from junction a tob.
Output
For each case, print the case number, the minimum number oflampposts required to light the whole city, the number of roadsthat are receiving lights from two lampposts and the number ofroads that are receiving light from only one lamppost.
Sample Input
2
4 3
0 1
1 2
2 3
5 4
0 1
0 2
0 3
0 4
Sample Output
Case 1: 2 1 2
Case 2: 1 0 4
题意: 城市规划, 在n个路灯节点, m条道路, 现在要使用最少的路灯放置在路灯节点上, 使得被2盏路灯
解题思路:
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define MAX 1005
#define M 2000
int n, m;
int dp[MAX][2];
vector g[MAX];
inline int min(int a, int b)
{
}
void readGraph()
{
}
int DP(int i, int j, int fa)
{
}
int main()
{
//
}
- ACM: 动态规划题 bnu 13149
- ACM: 动态规划题 toj1328
- ACM: 动态规划题 poj3280
- ACM: 简单动态规划题 poj 2955
- ACM: 动态规划题+剪枝 toj 3904
- ACM: 动态规划题 toj 1072
- ACM: 动态规划题 poj 2241
- ACM: 动态规划题 toj 1508
- ACM: 动态规划题 toj 1511
- ACM: 动态规划题 toj 1545
- ACM: 动态规划题 poj 1054
- ACM: 动态规划题 poj 2948
- ACM: 动态规划题 poj 1925
- ACM: 动态规划题 poj 3034
- ACM: 动态规划题 poj 2411
- ACM: 动态规划题 poj 1947
- ACM: 动态规划题 poj 2486
- ACM: 动态规划题 poj 3140
- Android五种储存方式—sqlite数据库存储
- ACM: poj 3141
- ACM: uva_10755
- ACM: poj 1903
- ACM: 动态规划题 uva 11825
- ACM: 动态规划题 bnu 13149
- ACM: 动态规划题 LA 3983
- ACM: 动态规划题 LA 4794
- ACM: uva 10382
- ACM: LA 4254 记住…
- Jersey 2.22.2 官方文档第18章学习笔记
- ACM: uva 11134
- ACM: 二分题 uva 11627
- 兴趣学习: 余弦定理的应用&nb…