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.他们有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.每个职员有一个快乐指数.现 ...
随机推荐
- NSArray和NSSet的区别
NSSet到底什么类型? 其实它和NSArray功能性质一样,用于存储对象,属于集合: NSSet , NSMutableSet类声明编程接口对象,无序的集合,在内存中存储方式是不连续的 像NSAr ...
- Google Analytics之增强型电子商务报告
虽然Google Analytics很多年以前就提供了电子商务报告的功能,但对于电子商务网站来说,这个报告缺失的东西还太多.而Google Analytics即将推出的增强型电子商务报告有望弥补这一短 ...
- swift 导航的使用
导航还是有必要来搞一下的!!!!! 这只是一些基本的导航的使用.....感兴趣的猿可以自己去 废话不多 源码奉上 ⬇️ 首先 delegate里面 在 func application(ap ...
- Java Ant Could not find the main class: org.eclipse.ant.internal.launching.remote.InternalAntRunner. Program
参考:http://blog.csdn.net/jiangtaoking/article/details/49151763 The solution is to go to Run as → Exte ...
- spring mvc 参数传递的三种方式
springmvc.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...
- MongoDB基础之九 replication复制集
准备工作:创建目录 mkdir -p /home/m17 //home/m18 /home/m19 /home/mlog 1:启动3个实例,且声明实例属于某复制集 # ./bin/mongod --d ...
- git命令实战之血泪记录
注意: 本文章所写所有命令均在Git命令行窗口执行!非cmd窗口! 打开git命令行窗口步骤为:到项目根目录下执行bash命令行操作:右键点击Git Bash Here菜单,打开git命令窗口,不是c ...
- linux下读取系统内存的demo
#include <stdio.h> #define KIBIBYTE_SIZE 1024LL #define MEBIBYTE_SIZE 1048576LL #define GIBIBY ...
- 安装软件(基于redhat、centos发行版)
yum 命令的使用: yum local install package_name.rpm 安装本地rpm包yum list updates 列出所有可以更新的安装包yum update packag ...
- C#剪贴板对文件的复制、粘贴操作
1.把文件加到剪贴板: System.Collections.Specialied.StringCollection files=new System.Collections.Specialied.S ...