CodeForces615B-Longtail Hedgehog-dp/图
记忆化数组记录从这个点的最长下降序列,然后乘以这个点的度,就是ans,维护即可。
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int maxn = 1e5+;
const int maxm = 4e5+;
int N,M; struct Edge{
int to,next;
}edge[maxm]; int NE,head[maxn],mem[maxn],chd[maxn];
long long ans; int add_edge(int u,int v)
{
edge[NE].to = v;
edge[NE].next = head[u];
head[u] = NE++;
chd[u]++; edge[NE].to = u;
edge[NE].next = head[v];
head[v] = NE++;
chd[v]++;
} long long dfs(int u)
{
if(mem[u] != -) {ans = max((long long)chd[u]*mem[u],ans);return mem[u];}
mem[u] = ;
for(int i=head[u];~i;i=edge[i].next)
{
int v = edge[i].to;
if(v > u) continue;
mem[u] = max((long long)mem[u],dfs(v)+);
} ans = max((long long)mem[u] * chd[u],ans);
return mem[u];
} int main()
{
scanf("%d%d",&N,&M);
memset(head,-,sizeof head);
memset(mem,-,sizeof mem); for(int i=,u,v;i<M;i++)
{
scanf("%d%d",&u,&v);
add_edge(u,v);
} for(int i=;i<=N;i++) dfs(i); printf("%I64d\n",ans);
}
CodeForces615B-Longtail Hedgehog-dp/图的更多相关文章
- Codeforces Round #338 (Div. 2) B. Longtail Hedgehog dp
B. Longtail Hedgehog 题目连接: http://www.codeforces.com/contest/615/problem/B Description This Christma ...
- Longtail Hedgehog(DP)
Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #338 (Div. 2) B. Longtail Hedgehog 记忆化搜索/树DP
B. Longtail Hedgehog This Christmas Santa gave Masha a magic picture and a pencil. The picture con ...
- codeforces 615 B. Longtail Hedgehog (DFS + 剪枝)
题目链接: codeforces 615 B. Longtail Hedgehog (DFS + 剪枝) 题目描述: 给定n个点m条无向边的图,设一条节点递增的链末尾节点为u,链上点的个数为P,则该链 ...
- codeforces 338(Div 2) B. Longtail Hedgehog 解题报告
题目链接:http://codeforces.com/problemset/problem/615/B 题目意思:要画一只 hedgehog,由 tail 和 spines 组成.我们要求得 beau ...
- hdu 5001 概率DP 图上的DP
http://acm.hdu.edu.cn/showproblem.php?pid=5001 当时一看是图上的就跪了 不敢写,也没退出来DP方程 感觉区域赛的题 一则有一个点难以想到 二则就是编码有 ...
- CodeForces 615B Longtail Hedgehog
题目: http://codeforces.com/problemset/problem/615/B 题意:题目描述很复杂,但实际上很简单.大意就是连续的几个点组成尾巴,要求尾巴的长度乘以尾巴终点的分 ...
- Codeforces Round #338 (Div. 2) B dp
B. Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standar ...
- Codeforces--615B--Longtail Hedgehog(贪心模拟)
B. Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #338 (Div. 2)
水 A- Bulbs #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1 ...
随机推荐
- Python_装饰器进阶_32
#带参数的装饰器 #500个函数 import time FLAGE = True def timmer_out(flag): def timmer(func): def inner(*args,** ...
- Wannafly summer camp Day6 - D 区间权值
这道题实在是不该,我在化式子的时候,多此一举,把式子进行累加,导致自己当时化的式子是错的,这样导致自己卡了很久,也没想到好的思路,赛后重新分析一波,感觉巨™简单...难受的一逼. 这道题的关键在于,W ...
- Python—反射
反射 1 什么是反射 反射的概念是由Smith在1982年首次提出的,主要是指程序可以访问.检测和修改它本身状态或行为的一种能力(自省).这一概念的提出很快引发了计算机科学领域关于应用反射性的研究.它 ...
- nginx强制使用https访问(http跳转到https)
Nginx 的 Location 从零开始配置 - 市民 - SegmentFault 思否https://segmentfault.com/a/1190000009651161 nginx配置loc ...
- python3 常见的两种文件上传方法
1.上传页面带input type格式send_keys传值方式上传不能大于60k(具体看开发设置的value)文件大小 fx.find_element_by_id('xx').send_keys(r ...
- package-lock.json和package.json的作用
转自:https://www.cnblogs.com/cangqinglang/p/8336754.html package-lock.json的作用就是锁定安装依赖时包的版本,并且需要上传到git, ...
- [转帖]震惊,用了这么多年的 CPU 利用率,其实是错的
震惊,用了这么多年的 CPU 利用率,其实是错的 2018年12月22日 08:43:09 Linuxer_ 阅读数:50 https://blog.csdn.net/juS3Ve/article/d ...
- [转帖]CentOS 6 服务器安全配置指南(通用)
CentOS 6 服务器安全配置指南(通用) http://seanlook.com/2014/09/07/linux-security-general-settings/ 发表于 2014-09- ...
- Oracle pivot行转列函数案例
with temp as( select '湖北省' province,'武汉市' city,'第一' ranking from dual union all select '湖北省' provinc ...
- TextView不用ScrollViewe也可以滚动的方法
转自:http://www.jb51.net/article/43377.htm android TextView不用ScrollViewe也可以滚动的方法. TextView textview = ...