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 ...
随机推荐
- 在VMware虚拟机中安装CentOS 7
[声明] 欢迎转载,但请保留文章原始出处 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3917 ...
- linux 常用端口列表
常见端口表汇总 1 tcpmux TCP Port Service Multiplexer 传输控制协议端口服务多路开关选择器 2 compressnet Management Utility com ...
- Window nginx+tomcat+https部署方案 支持ios9
客户端和 Nginx 之间走的 HTTPS 通讯,而 Nginx 到 Tomcat 通过 proxy_pass 走的是普通 HTTP 连接. 下面是详细的配置(Nginx 端口 80/443,Tomc ...
- Java 断点调试总结
为了准备调试,你需要在代码中设置一个断点先,以便让调试器暂停执行允许你调试,否则,程序会从头执行到尾,你就没有机会调试了. 1. 条件断点 断点大家都比较熟悉,在Eclipse Java 编辑区的行头 ...
- Hibernate中openSession() 与 getCurrentSession()的区别
1 getCurrentSession创建的session会和绑定到当前线程,而openSession每次创建新的session. 2 getCurrentSession创建的线程会在事务回滚或事物提 ...
- make subversion时出现neon报错 及 svn其他问题汇总(3ge )
在make subvision时,出现以下错误提示: /usr/local/src/neon-0.29.6/src/ne_auth.c:781: undefined reference to`ne__ ...
- c++类使用
一.C++定义类(注意:结束部分的分号不能省略) class 类名 { public: //公共的行为或属性 private: //公共的行为或属性 }; 注意:类的成员变量在定义时不能进行初始化, ...
- 基于gSOAP使用头文件的C语言版web service开发过程例子
基于gSOAP使用头文件的C语言版web service开发过程例子 一服务端 1 打开VS2005,创建一个工程,命名为calcServer. 2 添加一个头文件calc.h,编辑内容如下: 1// ...
- shell脚本操作mysql库
shell脚本操作mysql数据库-e参数执行各种sql(指定到处编码--default-character-set=utf8 -s,去掉第一行的字段名称信息-N) 2011-05-11 18:18: ...
- Ubuntu下gdb远程调试--warning: Could not load vsyscall page because no executable was specified解决方案
1. 首先安装gdbserver apt-get install gdbserver 2. 编译-g 程序 gcc -g test_gdb.c -o test_gdb 源码如下: #include & ...