记忆化数组记录从这个点的最长下降序列,然后乘以这个点的度,就是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/图的更多相关文章

  1. Codeforces Round #338 (Div. 2) B. Longtail Hedgehog dp

    B. Longtail Hedgehog 题目连接: http://www.codeforces.com/contest/615/problem/B Description This Christma ...

  2. Longtail Hedgehog(DP)

    Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...

  3. 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 ...

  4. codeforces 615 B. Longtail Hedgehog (DFS + 剪枝)

    题目链接: codeforces 615 B. Longtail Hedgehog (DFS + 剪枝) 题目描述: 给定n个点m条无向边的图,设一条节点递增的链末尾节点为u,链上点的个数为P,则该链 ...

  5. codeforces 338(Div 2) B. Longtail Hedgehog 解题报告

    题目链接:http://codeforces.com/problemset/problem/615/B 题目意思:要画一只 hedgehog,由 tail 和 spines 组成.我们要求得 beau ...

  6. hdu 5001 概率DP 图上的DP

    http://acm.hdu.edu.cn/showproblem.php?pid=5001 当时一看是图上的就跪了 不敢写,也没退出来DP方程 感觉区域赛的题  一则有一个点难以想到 二则就是编码有 ...

  7. CodeForces 615B Longtail Hedgehog

    题目: http://codeforces.com/problemset/problem/615/B 题意:题目描述很复杂,但实际上很简单.大意就是连续的几个点组成尾巴,要求尾巴的长度乘以尾巴终点的分 ...

  8. Codeforces Round #338 (Div. 2) B dp

    B. Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input standar ...

  9. Codeforces--615B--Longtail Hedgehog(贪心模拟)

     B. Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input stan ...

  10. Codeforces Round #338 (Div. 2)

    水 A- Bulbs #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1 ...

随机推荐

  1. 使用docker Registry快速搭建私有镜像仓库

    当我们执行docker pull xxx的时候,docker默认是从registry.docker.com这个地址上去查找我们所需要的镜像文件,然后执行下载操作.这类的镜像仓库就是docker默认的公 ...

  2. docker部署nginx

    1. 下载nginx [root@localhost my.Shells]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/ ...

  3. 微信支付异常:appid and openid not match

    上周调试微信小程序支付时遇到的问题,在调用统一下单接口获取微信支付的相关参数时,报了这么一个错误:appid and openid not match. 字面意思很容易理解,就是appid与openi ...

  4. PV、UV、IP、TPS、QPS、RPS、两天、吞吐量、 并发用户数 术语

    跟网站打交道,经常可以听到数据分析之类的专有名词,如pv多少.ip多少.tps多少之类的问题.下面就这些常见的数据给出其释义. PV   即 page view,页面浏览量         用户每一次 ...

  5. elasticsearch(6.2.3)安装Head插件

    一.安装elasticsearch,参照:https://www.cnblogs.com/dyh004/p/8872443.html 二.安装nodejs,参照:https://www.runoob. ...

  6. Python-time模块-58

    time 模块: Eva_J import time time.sleep(100) #时间睡眠 print(time.time()) #返回一个以秒为单位的时间 时间模块 和时间有关系的我们就要用到 ...

  7. 分解质因数FZU - 1075

    题目简述:就是给一个数,把他拆分成多个素数的乘积,这正好是算术基本定理.本题我的解决方法是埃氏素数筛+质因数保存...开始T掉了,是因为我在最后枚举了素数,保存他们的次数,然后两次for去查询他们的次 ...

  8. Day10 Python基础之特殊函数(八)

    一些特殊函数 1.递归函数(recursion) 递归函数的定义:在函数内部,可以调用其他函数.如果一个函数在内部调用自身本身,这个函数就是递归函数. 递归函数的优点:是定义简单,逻辑清晰.理论上,所 ...

  9. net core 小坑杂记之配置文件读取(不定期更新)

    其实很早就想写了,原想等积累差不多了再写的,但是发现遇到一个当时记下效果会比较好,所以就不定期更新这个系列了,后面获取会整个整理一下. 此篇记载net core入门时踩的一些坑,网上教程太少了,也不规 ...

  10. CRM系统(第三部分)

      阅读目录 1.销售与客户的表结构 2.公共客户池 3.确认跟进 4.我的客户 5.code 1.销售与客户的表结构 1.公共客户与我的客户 ---公共客户(公共资源) 1.没有报名 2.3天没有跟 ...