Codeforces Round #338 (Div. 2) B. Longtail Hedgehog dp
B. Longtail Hedgehog
题目连接:
http://www.codeforces.com/contest/615/problem/B
Description
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.
Input
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.
Output
Print the maximum possible value of the hedgehog's beauty
Sample Input
8 6
4 5
3 5
2 5
1 2
2 8
6 7
Sample Output
9
Hint
题意
给你一个图,然后你可以选择连续的一段,成为刺猬的脊梁,这个脊梁的要求是点上的编号必须依次增大
然后他的贡献是这个脊梁的长度*脊梁最后一个点的边数。
问你这个图最大的贡献是多少
题解:
直接dp处理就好了,dp[i]表示到i点的最长长度,很显然dp[i] = max(dp[i],dp[j]+1)(j<i)
然后从小到大一直跑就好了
代码
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
int dp[maxn];
vector<int> E[maxn];
int cnt[maxn];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
int x,y;scanf("%d%d",&x,&y);
if(x<y)swap(x,y);
E[x].push_back(y);
cnt[x]++,cnt[y]++;
}
long long ans = 0;
for(int i=1;i<=n;i++)
{
for(int j=0;j<E[i].size();j++)
dp[i]=max(dp[i],dp[E[i][j]]);
dp[i]++;
ans = max(ans,1LL*dp[i]*cnt[i]);
}
cout<<ans<<endl;
}
Codeforces Round #338 (Div. 2) B. Longtail Hedgehog dp的更多相关文章
- 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 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)
水 A- Bulbs #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1 ...
- 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 Round #174 (Div. 1) B. Cow Program(dp + 记忆化)
题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...
- Codeforces Round #338 (Div. 2) E. Hexagons 讨论讨论
E. Hexagons 题目连接: http://codeforces.com/contest/615/problem/E Description Ayrat is looking for the p ...
- Codeforces Round #338 (Div. 2) D. Multipliers 数论
D. Multipliers 题目连接: http://codeforces.com/contest/615/problem/D Description Ayrat has number n, rep ...
- Codeforces Round #338 (Div. 2) A. Bulbs 水题
A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...
- Codeforces Round #338 (Div. 2) D 数学
D. Multipliers time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
随机推荐
- 6、Android中的NFC技术
Android对NFC技术的支持 Android2.3.1(API Level = 9)开始支持NFC技术,但Android2.x和Android3.x对NFC的支持非常有限.而从Android4.0 ...
- Java 设计模式学习总结(上)
在编写和维护公司的现有代码的时候,我经常思考的问题是:怎样的系统算一个好的系统?如何设计具有扩展.可维护.复用的系统,它能最大限度的应对产品经理不断变化的需求.答案似乎是:设计模式. Remember ...
- 怎样为EXCEL2010添加下拉列表
注意,下面是Excel2010的步骤和截图,其他版本的Excel类似. 首先用鼠标左键点击你要添加下拉列表的单元格. 如果你只想部分区域有下拉列表,也可以选择部分区域. 下面图片是选择的整个列都是 ...
- 用Asp.net实现简单的文字水印
用Asp.net实现简单的文字水印 经常看见MOP上有人贴那种动态的图片,就是把一个字符串作为参数传给一个动态网页,就会生成一个带有这个字符串的图片,这个叫做文字水印.像什么原来的熊猫系列,还有后来 ...
- CRF模型
CRF的全称是Conditional Random Fields,由CMU教授John Lafferty 提出,原文标题:Conditional R andom Fields: Probabilist ...
- Python的OO思想
想当年大二的时候,在学校学习Java, 最牛逼的OO思想,用了3页纸就讲完了,还是清华大学出版社的呢. 后来全凭自己啃视频,啃代码才搞懂什么叫做OO. 现在学习Python,就用自己的方式,好好学习一 ...
- samba服务设置,Linux系统和Windows文件共享
samba是一个工具套件,在Unix上实现SMB(Server Message Block)协议,或者称之为NETBIOS/LanManager协议.SMB协议通常是被windows系列用来实现磁盘和 ...
- MySQL/MariaDB/Percona数据库升级脚本
MySQL/MariaDB/Percona数据库升级脚本截取<OneinStack>中upgrade_db.sh, 一般情况下不建议升级数据库版本,该脚本专提供给各位版本控们.为防止大版本 ...
- (window)Android Studio安装以及Fetching android sdk component information超时的解决方案
转自:http://www.cnblogs.com/sonyi/p/4154797.html 在经过两年的开发之本后,Google 公司终于发布了 Android Studio 1.0,喜欢折腾的童鞋 ...
- 修改hosts文件解决OneDrive被墙的问题
增加如下内容就可以了.如果不知道修改hosts文件的具体方法请自行百度. 134.170.108.26 onedrive.live.com 134.170.108.152 skyapi.onedriv ...