记忆化数组记录从这个点的最长下降序列,然后乘以这个点的度,就是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. 如何选择分布式事务形态(TCC,SAGA,2PC,补偿,基于消息最终一致性等等)

    各种形态的分布式事务 分布式事务有多种主流形态,包括: 基于消息实现的分布式事务 基于补偿实现的分布式事务(gts/fescar自动补偿的形式) 基于TCC实现的分布式事务 基于SAGA实现的分布式事 ...

  2. windows 命令行操作 Mysql 数据库

    1 前言 有接手一个新项目,项目中到了 Mysql 数据库 ,这里总结下 windows 命令行操作 Mysql 数据库. 2 Cmd操作数据库 2.1 连接Mysql服务器,命令如下:(root用户 ...

  3. 2019 年起如何开始学习 ABP 框架系列文章-开篇有益

    2019 年起如何开始学习 ABP 框架系列文章-开篇有益 [[TOC]] 本系列文章推荐阅读地址为:52ABP 开发文档 https://www.52abp.com/Wiki/52abp/lates ...

  4. koa服务器搭建基础

    之前我一直使用rails搭建网站.rails与koa的基本理念很相似,都是基于中间件提供一层层的服务.所不同的是,rails有很多内置的中间件,这使得开发者只需要关注MVC模块以及页面路由.而Koa这 ...

  5. 一些leetcode算法题

    DFS算法 思想:一直往深处走,直到找到解或者走不下去为止 DFS(dep,...) // dep代表目前DFS的深度 { if (找到解或者走不下去了){ return; } 枚举下种情况,DFS( ...

  6. H5 31-CSS元素显示模式转换

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 牛客国庆集训派对Day2

    题目链接:https://www.nowcoder.com/acm/contest/202/A A 题意:给出最大4096*64和64*4096的矩阵,其中有一个矩阵只含有0和1,问你它们相乘所得到得 ...

  8. Git更新本地仓库

    1.查看远程仓库git remote -v2.从远程获取最新版本到本地git fetch origin master:temp3.比较本地的仓库与远程仓库的区别git diff temp4.合并tem ...

  9. 百度地图开发者API学习笔记一(转载)

    一,实现功能: 在地图上标记点,划线等操作.如下图. 2.代码: <!DOCTYPE html> <html> <head> <meta http-equiv ...

  10. Java使用Redis实现分布式锁来防止重复提交问题

    如何用消息系统避免分布式事务? - 少年阿宾 - BlogJavahttp://www.blogjava.net/stevenjohn/archive/2018/01/04/433004.html [ ...