Codeforces Round #338 (Div. 2) B dp
3 seconds
256 megabytes
standard input
standard output
This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects the point to itself. Masha wants to color some segments in order paint a hedgehog. In Mashas mind every hedgehog consists of a tail and some spines. She wants to paint the tail that satisfies the following conditions:
- Only segments already presented on the picture can be painted;
- The tail should be continuous, i.e. consists of some sequence of points, such that every two neighbouring points are connected by a colored segment;
- The numbers of points from the beginning of the tail to the end should strictly increase.
Masha defines the length of the tail as the number of points in it. Also, she wants to paint some spines. To do so, Masha will paint all the segments, such that one of their ends is the endpoint of the tail. Masha defines the beauty of a hedgehog as the length of the tail multiplied by the number of spines. Masha wants to color the most beautiful hedgehog. Help her calculate what result she may hope to get.
Note that according to Masha's definition of a hedgehog, one segment may simultaneously serve as a spine and a part of the tail (she is a little girl after all). Take a look at the picture for further clarifications.
First line of the input contains two integers n and m(2 ≤ n ≤ 100 000, 1 ≤ m ≤ 200 000) — the number of points and the number segments on the picture respectively.
Then follow m lines, each containing two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the numbers of points connected by corresponding segment. It's guaranteed that no two segments connect the same pair of points.
Print the maximum possible value of the hedgehog's beauty.
8 6
4 5
3 5
2 5
1 2
2 8
6 7
9
4 6
1 2
1 3
1 4
2 3
2 4
3 4
12
The picture below corresponds to the first sample. Segments that form the hedgehog are painted red. The tail consists of a sequence of points with numbers 1, 2 and 5. The following segments are spines: (2, 5), (3, 5) and (4, 5). Therefore, the beauty of the hedgehog is equal to 3·3 = 9.
题意:给你一个图 求 ans的最大值 ans=图中一条点权严格递增的链的长度乘以终点的度
题解:dp[i] 为以i为终点的满足条件的链的长度 并且计算每个点的度 枚举乘积取max输出
#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
using namespace std;
int n,m;
map<int,ll>du;
struct node
{
int to;
int pre;
}N[];
int pre[];
int nedge=;
void add(int s,int t)
{
nedge++;
N[nedge].to=t;
N[nedge].pre=pre[s];
pre[s]=nedge;
}
ll dp[];
int main()
{
scanf("%d %d",&n,&m);
int x,y;
du.clear();
for(int i=;i<=n;i++){
dp[i]=;
}
for(int i=;i<=m;i++){
scanf("%d %d",&x,&y);
add(x,y);
add(y,x);
du[x]++;
du[y]++;
}
for(int i=;i<=n;i++)
{
for(int j=pre[i];j;j=N[j].pre)
{
if(N[j].to<i)
{
dp[i]=max(dp[i],dp[N[j].to]+);
}
}
}
ll ans=;
for(int i=;i<=n;i++){
ans=max(ans,du[i]*dp[i]);
}
printf("%I64d\n",ans);
return ;
}
Codeforces Round #338 (Div. 2) B dp的更多相关文章
- Codeforces Round #338 (Div. 2) C. Running Track dp
C. Running Track 题目连接: http://www.codeforces.com/contest/615/problem/C Description A boy named Ayrat ...
- Codeforces Round #338 (Div. 2) B. Longtail Hedgehog dp
B. Longtail Hedgehog 题目连接: http://www.codeforces.com/contest/615/problem/B Description This Christma ...
- 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 ...
- 严格递增类的dp Codeforces Round #371 (Div. 1) C dp
http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...
- 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp
http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...
- Codeforces Round #548 (Div. 2) C dp or 排列组合
https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...
- Codeforces Round #536 (Div. 2) E dp + set
https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希
https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...
随机推荐
- Pycharm实现服务器端代码的远程调试
Pycharm是很多人在学习机器学习时的常用IDE.但是,当代码需要庞大计算资源的时候,我们往往需要借助远程服务器的GPU资源.很多人都是将代码拷贝到服务器,然后运行,但是当修改调试的时候,很不方便 ...
- C++数字三角形问题与dp算法
题目:数字三角形 题目介绍:如图所示的数字三角形,要求从最上方顶点开始一步一步下到最底层,每一步必须下一层,求出所经过的数字的最大和. 输入:第一行值n,代表n行数值:后面的n行数据代表每一行的数字. ...
- Redis 指令
一个key可以存放将近40亿条数据 选择库 select 2 (代表选择第三个库) 增加key set db_number 11 删除key del key 获取值 get db_n ...
- 亚马逊中国耳机巨头Jabra官方旗舰店上线
日前,亚马逊中国(Z.cn)宣布,全球无线技术顶级领导品牌 Jabra (捷波朗)官方旗舰店正式上线,产品品类涵盖蓝牙耳机.音乐耳机.无线音箱和车载系列产品.Jabra 旗舰店上线伊始便汇集了 60 ...
- Centos7 Zabbix添加主机、图形、触发器
制作自定义key zabbix自带模板Template OS Linux (Template App Zabbix Agent)提供CPU.内存.磁盘.网卡等常规监控,只要新加主机关联此模板,就可自动 ...
- Python20-Day02
1.数据 数据为什么要分不同的类型 数据是用来表示状态的,不同的状态就应该用不同类型的数据表示: 数据类型 数字(整形,长整形,浮点型,复数),字符串,列表,元组,字典,集合 2.字符串 1.按索引取 ...
- 2016-6-2-第二个sprint
1.开始一个新的冲刺: 起止:2016.6.1~2016.6.14 ProductBacklog:继续向下细化 Sprint 计划会议:确定此次冲刺要完成的目标 Sprint Backlog:新的冲刺 ...
- 20172326『Java程序设计』课程结对编程练习_四则运算第二周阶段总结
20172326『Java程序设计』课程结对编程练习_四则运算第二周阶段总结 小组成员 20172313 余坤澎 20172332 于欣月 20172326 康皓越 小组编程照片 设计思路 通过一个E ...
- 03慕课网《vue.js2.5入门》——Vue-cli的安装,创建webpack模板项目
安装Vue-cli 第一种 貌似不可以,然后用了第二种,但是重装系统后,第二种不能用了,用了第一种可以 # 全局安装vue -cli命令npm install --global vue-cli # 创 ...
- C++Primer第五版——习题答案和解析
感谢原文博主的分享:https://blog.csdn.net/misayaaaaa/article/details/53786215 新手入门必看的书.知识是一个系统化并且相互关联的体系,零散的东西 ...