2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛
2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛
Time Limit: 3 Sec Memory Limit: 64 MB
Submit: 252 Solved: 185
[Submit][Status]
Description
Input
Output
Sample Input
6 2
3 4
2 3
1 2
7 6
5 6
INPUT DETAILS:
Bessie knows 7 cows. Cows 6 and 2 are directly connected by a road,
as are cows 3 and 4, cows 2 and 3, etc. The illustration below depicts the
roads that connect the cows:
1--2--3--4
|
5--6--7
Sample Output
OUTPUT DETAILS:
Bessie can visit four cows. The best combinations include two cows
on the top row and two on the bottom. She can't visit cow 6 since
that would preclude visiting cows 5 and 7; thus she visits 5 and
7. She can also visit two cows on the top row: {1,3}, {1,4}, or
{2,4}.
HINT
Source
题解:树状DP啦啦树状DP,按照下面的子节点选和不选进行转移完事
/**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ type
point=^node;
node=record
g:longint;
next:point;
end;
vec=record
a0,a1:longint;
end;
var
i,j,k,l,m,n:longint;
a:array[..] of point;
b:array[..] of longint;
t:vec;
function max(x,y:longint):longint;inline;
begin
if x>y then max:=x else max:=y;
end;
procedure add(x,y:longint);inline;
var p:point;
begin
new(p);p^.g:=y;
p^.next:=a[x];a[x]:=p;
end;
function dfs(x:longint):vec;inline;
var p:point;t,v:vec;
begin
b[x]:=;
p:=a[x];
t.a0:=;t.a1:=;
while p<>nil do
begin
if b[p^.g]= then
begin
v:=dfs(p^.g);
t.a1:=t.a1+v.a0;
t.a0:=t.a0+max(v.a1,v.a0);
end;
p:=p^.next;
end;
exit(t);
end;
begin
readln(n);
for i:= to n do a[i]:=nil;
fillchar(b,sizeof(b),);
for i:= to n- do
begin
readln(j,k);
add(j,k);add(k,j);
end;
t:=dfs();
writeln(max(t.a0,t.a1));
end.
2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛的更多相关文章
- BZOJ 2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛( dp )
树形dp..水 ------------------------------------------------------------------------ #include<cstdio& ...
- 【BZOJ】2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛(树形dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=2060 裸的树形dp d[x][1]表示访问x的数量,d[x][0]表示不访问x的数量 d[x][1] ...
- 【BZOJ】2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛
[算法]树形DP [题解]没有上司的舞会?233 f[x][0]=∑max(f[v][0],f[v][1]) f[x][1]=(∑f[v][0])+1 #include<cstdio> # ...
- bzoj 2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛【树形dp】
设f[u][0/1]为u这个点不选/选,转移的时候从儿子转移,f[u][1]=sum(f[son][0])+1,f[u][0]=sum(max(f[son][0],f[e[i].to][1])) #i ...
- BZOJ 2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛 树形DP
Code: #include <bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) ...
- [bzoj2060][Usaco2010 Nov]Visiting Cows 拜访奶牛_树形dp
Visiting Cows 拜访奶牛 bzoj-2060 Usaco-2010 Nov 题目大意:题目链接. 注释:略. 想法:看起来像支配集. 只是看起来像而已. 状态:dp[pos][flag]表 ...
- 【bzoj2060】[Usaco2010 Nov]Visiting Cows拜访奶牛
题目描述 经过了几周的辛苦工作,贝茜终于迎来了一个假期.作为奶牛群中最会社交的牛,她希望去拜访N(1<=N<=50000)个朋友.这些朋友被标号为1..N.这些奶牛有一个不同寻常的交通系统 ...
- 【bzoj2060】[Usaco2010 Nov]Visiting Cows拜访奶牛 树形dp
题目描述 经过了几周的辛苦工作,贝茜终于迎来了一个假期.作为奶牛群中最会社交的牛,她希望去拜访N(1<=N<=50000)个朋友.这些朋友被标号为1..N.这些奶牛有一个不同寻常的交通系统 ...
- [codevs1380]没有上司的舞会([BZOJ2060][Usaco2010 Nov]Visiting Cows 拜访奶牛)
[codevs1380]没有上司的舞会 试题描述 Ural大学有N个职员,编号为1~N.他们有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.每个职员有一个快乐指数.现 ...
随机推荐
- Cisco VPN Client Error 56解决
Cisco VPN Client Error 56解决 VPN Client报错 650) this.width=650;" style="width:575px;height:1 ...
- Pomelo的component组件
pomelo的核心是由一系列松耦合的component组成,同时我们也可以实现我们自己的component来完成一些自己定制的功能.对于我们的聊天应用,我们尝试给其增加一个component,目的是展 ...
- Canvas 阴影效果
shadow <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- PowerShell:因为在此系统上禁止运行脚本
在安装chocolatey(官网)的时候,不能运行chocolateyInstall.pal脚本文件. 查阅资料后,得出如下解决办法: 首次在计算机上启动 Windows PowerShell 时,现 ...
- I/O模型浅析
引入 首先来说一下进程: 进程在就是一段执行中的代码,他是由一条条指令和数据组成的一个具有生命周期的有头有尾的实体. 进程根据权限大体上可以分为两类:用户进程 和 内核进程. 这两者的主要区别在于权限 ...
- SQLite:自学笔记(1)——快速入门
SQLite的安装和入门 了解 啥是SQLite? SQLite是一种轻巧迷你的关系型数据库管理系统.它的特点如下: 不需要一个单独的服务器进程或操作的系统(无服务器的). SQLite 不需要配置, ...
- Express之get,pos请求参数的获取
Express的版本4.X Get query参数的获取 url假设:http://localhost:3000/users/zqzjs?name=zhaoqize&word=cool& ...
- VS Code C# 插件离线版 1.6.2
VS Code C# 插件离线版,目前最新稳定版为:1.6.2 . 由于在扩展中下载C#插件总是缓慢,或者容易出现错误,特制作离线版本共享出来. 本离线版本为Windows版本,其他系统请在扩展中下载 ...
- How To Ask Questions The Smart Way 转
先查后问多思考莫做伸手党. 原文链接 译文链接
- arcpy.mapping-认识arcpy.mapping
arcpy.mapping-认识arcpy.mapping by 李远祥 ArcMap提供了强大的地图制图功能,在实际的工作中,只要涉及到专题地图和地图册的制作,难免会遇到非常多的出图工作和地图图面元 ...