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.他们有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.每个职员有一个快乐指数.现 ...
随机推荐
- CentOS6.5+mysql5.5源码安装
数据库安装 1新增mysql用户 [root@HE1mysql]# groupadd mysql -g 502 [root@HE1mysql]# useradd -g mysql -s /sbin/n ...
- Java线程:线程中断
interrupt方法可以用来请求终止线程. 当对一个线程调用interrupt方法时,线程的中断状态被置位.这时每个线程都有boolean标志.每个线程都应该不时的检查这个标志,以判断线程是否被中断 ...
- iostat中 %util高 应用延迟高
经过长时间监控,发现iostat 中的%util居高不下,一直在98%上下,说明带宽占用率极高,遇到了瓶颈. 且读写速度很慢,经过排查,发现是HBA卡出现问题,更换后,用dd if命令测试,磁盘的读写 ...
- JSP userBean setProperty getProperty指令使用
JSP userBean setProperty getProperty指令使用 javaBean的属性取决于get/set方法,而不是真实的属性名称. jsp文件: <%@ page lang ...
- .NET操作RabbitMQ组件EasyNetQ使用中文简版文档。
本文出自EasyNetQ官方文档,内容为自己理解加翻译.文档地址:https://github.com/EasyNetQ/EasyNetQ/wiki/Quick-Start EasyNetQ简介 Ea ...
- SQL关键字转换大写核心算法实现
1 不跟你多废话 上代码! /// <summary> /// SQL关键字转换器 /// </summary> public class SqlConverter : IKe ...
- react构建淘票票webapp,及react与vue的简单比较。
前言 前段时间使用vue2.0构建了淘票票页面,并写了一篇相关文章vue2.0构建淘票票webapp,得到了很多童鞋的支持,因此这些天又使用react重构了下这个项目,目的无他,只为了学习和共同进步! ...
- Struts系列笔记(6)---action接收请求参数
action接收请求参数 在web开发中,去接收请求参数来获得表单信息非常的常见,自己也总结整理了有关Struts2通过action接收请求参数的几种方法. Struts2 提供三种数据封装的方式: ...
- 初探 discuz
测试: vim /etc/hosts ##ip地址转换 修改windows 的配置文件,写字板打开 vim /usr/local/apache/conf/httpd.conf vim /u ...
- ionic-cordova 支付宝支付插件cordova-plugin-alipay-v2使用篇
支付宝WS_APP_PAY_SDK_BASE_2.0 <APP支付> 支付宝的cordova插件其实在github上已经有很多了,但是都已经是以前的版本了.在2016年11月的时候支付宝进 ...