hdu 4274 2012长春赛区网络赛 树形dp ***
设定每个节点的上限和下限,之后向上更新,判断是否出现矛盾
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int N=;
int n,m,tt,tot=,head[N],dp[N];
int maxw;
bool flag;
struct edge
{
int to,next;
}edge[N*];
int up[N],low[N];
void addedge(int a,int b)
{
edge[tot].to=a;
edge[tot].next=head[b];
head[b]=tot++;
}
void init()
{
memset(head,-,sizeof(head));
tot=;
}
void dfs(int u,int pre)
{
if(flag) return;
if(up[u]!=-&&low[u]>up[u])
{
flag=;
return;
}
int le=;
int sum=;
for(int i=head[u];i!=-;i=edge[i].next)
{
int v=edge[i].to;
if(v==pre) continue;
le=;
dfs(v,u);
sum+=low[v];
}
if(!le) return;
low[u]=max(sum+,low[u]);
if(up[u]!=-&&low[u]>up[u])
{
flag=;
return;
}
}
int main()
{
int i,j,k;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
while(scanf("%d",&n)!=EOF)
{
init();
for(i=;i<=n;i++)
{
int u;
scanf("%d",&u);
addedge(i,u);
addedge(u,i);
}
for(i=;i<=n;i++) up[i]=-,low[i]=;
scanf("%d",&m);
for(i=;i<m;i++)
{
int u,v,w;
char c[];
scanf("%d%s%d",&u,c,&w);
if(c[]=='<') up[u]=w-;
else if(c[]=='>') low[u]=w+;
else low[u]=up[u]=w;
}
flag=;
dfs(,-);
if(flag)
{
printf("Lie\n");
}
else printf("True\n");
}
}
hdu 4274 2012长春赛区网络赛 树形dp ***的更多相关文章
- hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***
新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...
- hdu 4277 2012长春赛区网络赛 dfs+hashmap ***
hashmap判重大法好 #include<cstdio> #include<iostream> #include<algorithm> #include<c ...
- hdu 4272 2012长春赛区网络赛 dfs暴力 ***
总是T,以为要剪枝,后来发现加个map就行了 #include<cstdio> #include<iostream> #include<algorithm> #in ...
- hdu 4412 2012杭州赛区网络赛 期望
虽然dp方程很好写,就是这个期望不知道怎么求,昨晚的BC也是 题目问题抽象之后为:在一个x坐标轴上有N个点,每个点上有一个概率值,可以修M个工作站, 求怎样安排这M个工作站的位置,使得这N个点都走到工 ...
- hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***
题意: 有 n+1 个城市编号 0..n,有 m 条无向边,在 0 城市有个警察总部,最多可以派出 k 个逮捕队伍,在1..n 每个城市有一个犯罪团伙, 每个逮捕队伍在每个城市可以选 ...
- hdu 4293 2012成都赛区网络赛 dp ****
题意:有n个人,可任意分成若干组,然后每个人个各提供一个信息,表示他们组前面有多少人,后面有多少人.问最多有多少个信息是不冲突的. 将n个人看成一组区间,然后每个人的信息可以表示为该人所在组的区间,然 ...
- hdu 4291 2012成都赛区网络赛 矩阵快速幂 ***
分析:假设g(g(g(n)))=g(x),x可能非常大,但是由于mod 10^9+7,所以可以求出x的循环节 求出x的循环节后,假设g(g(g(n)))=g(x)=g(g(y)),即x=g(y),y也 ...
- hdu 4278 2012天津赛区网络赛 数学 *
8进制转为10进制 #include<cstdio> #include<iostream> #include<algorithm> #include<cstr ...
- hdu 4028 2011上海赛区网络赛H dp+map离散
一开始用搜索直接超时,看题解会的 #include<iostream> #include<cstdio> #include<map> #include<cst ...
随机推荐
- symfony2 环境搭建笔记
本机环境:windows+xampp symfony下载:官网下载 环境配置: 1.下载后将symfony文件夹解压到xampp/htdocs中(最好改一下文件夹名,尽量小写) 2.Symfony2自 ...
- Java读取mat文件
概述 使用ujmp中的jmatio模块读取.mat文件到java程序中. 其实,ujmp主要是在模块core中实现了矩阵运算,其余模块都是复用了已有的开源库.模块jmatio是复用了已有的JMatIo ...
- chkconfig用法 LINUX
chkconfig用法 有时候为了方便管理,我们常常喜欢在Linux中将之安装为服务,然后就可以使用服务来管理. 但是当我们运行安装服务的命令时候,假设服务名为myservice #chkconfig ...
- 使用html5 FileReader获取图片,并异步上传到服务器(不使用iframe)
使用html5 FileReader获取图片,并异步上传到服务器(不使用iframe) 原理: 1.使用FileReader 读取图片的base64编码 2.使用ajax,把图片的base64编码 ...
- 深入理解学习Git工作流
http://blog.csdn.net/hongchangfirst/article/list/3 //可以看看 http://blog.csdn.net/hongchangfirst/articl ...
- poj 3984
http://poj.org/problem?id=3984 题目很简单,就是简单的BFS吧,主要的难点在于坐标的问题 这个呢,可以反其道而行之,就是你从(1,1)到(5,5),你肯定走过一次 走过一 ...
- 关于Intent ,Task, Activity的理解
看到一篇好文章,待加工 http://hi.baidu.com/jieme1989/item/6e5f41d3f65be848ddf9beb9 第三篇 http://blog.csdn.net/luo ...
- 没有body怎么添加onload事件
<script type="text/javascript"> window.onload = function () { setup(); } </script ...
- jQueryUI Datepicker的使用
jQueryUI Datepicker是一个高度可定制的插件,可以很方便的为你的页面添加日期选择功能,你可以自定义日期的显示格式 以及要使用的语言. 你可以使用键盘的快捷键来驱动datepicker插 ...
- JS图表插件(柱形图、饼状图、折线图)
http://www.open-open.com/lib/view/open1406378625726.html