Codeforces 566F Clique in the Divisibility Graph
http://codeforces.com/problemset/problem/566/F
题目大意:
有n个点,点上有值a[i], 任意两点(i, j)有无向边相连当且仅当
(a[i] mod a[j])==0||(a[j] mod a[i])==0
问这幅图中的最大连通子图是多少。
思路:直接转移,时间复杂度O(n^1.5)
- #include<cstdio>
- #include<cmath>
- #include<cstring>
- #include<algorithm>
- #include<iostream>
- int n,a[],f[];
- int read(){
- int t=,f=;char ch=getchar();
- while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
- while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
- return t*f;
- }
- int main(){
- n=read();int mx=;
- for (int i=;i<=n;i++){
- a[i]=read();
- mx=std::max(mx,a[i]);
- }
- std::sort(a+,a++n);
- int ans=;
- for (int i=;i<=n;i++){
- f[a[i]]++;
- for (int j=a[i]+a[i];j<=mx;j+=a[i])
- f[j]=std::max(f[j],f[a[i]]);
- ans=std::max(ans,f[a[i]]);
- }
- printf("%d\n",ans);
- }
Codeforces 566F Clique in the Divisibility Graph的更多相关文章
- Codeforces.566F.Clique in the Divisibility Graph(DP)
题目链接 \(Description\) 给定集合\(S=\{a_1,a_2,\ldots,a_n\}\),集合中两点之间有边当且仅当\(a_i|a_j\)或\(a_j|a_i\). 求\(S\)最大 ...
- F. Clique in the Divisibility Graph DP
http://codeforces.com/contest/566/problem/F F. Clique in the Divisibility Graph time limit per test ...
- 周赛-Clique in the Divisibility Graph 分类: 比赛 2015-08-02 09:02 23人阅读 评论(3) 收藏
Clique in the Divisibility Graph time limit per test1 second memory limit per test256 megabytes inpu ...
- CodeForces - 527D Clique Problem (图,贪心)
Description The clique problem is one of the most well-known NP-complete problems. Under some simpli ...
- CodeForces 505B Mr. Kitayuta's Colorful Graph
Mr. Kitayuta's Colorful Graph Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Round #192 (Div. 1) C. Graph Reconstruction 随机化
C. Graph Reconstruction Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/3 ...
- Codeforces 527D Clique Problem
http://codeforces.com/problemset/problem/527/D 题意:给出一些点的xi和wi,当|xi−xj|≥wi+wj的时候,两点间存在一条边,找出一个最大的集合,集 ...
- codeforces 505B Mr. Kitayuta's Colorful Graph(水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Mr. Kitayuta's Colorful Graph Mr. Kitayut ...
随机推荐
- delphi7编写客户端调用java服务器端webservice示例
1. 首先取得java-webservice服务器端地址.我的是:http://localhost:8080/mywebservice/services/mywebservice?wsdl 2. 然后 ...
- 《SDN核心技术剖析和实战指南》2.1交换机核心技术小结
对于SDN交换机的技术,其实也适用于传统的交换机,只不过控制部分被分离出来而已.传统交换机的控制面主要是转发表的管理以及网络状态之类的各种表,现在这些都由控制器来担心.转发面主要由转发决策.背板和输出 ...
- 寻访上海西服定制店_Enjoy·雅趣频道_财新网
寻访上海西服定制店_Enjoy·雅趣频道_财新网 寻访上海西服定制店
- MySQL 遇到的问题:在服务里找不到自己的 MySQL,以及在命令行窗口中运行服务出现的问题。
1.用数据库的时候在服务里找不到自己的 MySQL ,于是就想用命令行窗口去运行. ①.在开始里,键入 cmd ,打开命令行窗口. ②.输入:mysql -u root -p 回车,这时会提示请输入密 ...
- iOS语音识别,语音播报,文字变语音播报,语音变文字
首先使用的是科大讯飞的sdk 1.语音识别部分 AppDelegate.m #import "AppDelegate.h" #import <iflyMSC/iflyMSC. ...
- windows服务程序
首先创建一个myService的窗体程序作为服务安装卸载控制器(管理员身份运行vs,windows服务的安装卸载需要管理员权限) 在同一个解决方案里面添加一个windows服务程序,取名myWin ...
- cavium octeon 处理器启动总线Bootbus 简介
cavium octeon 处理器启动总线Bootbus 简介: 韩大卫@吉林师范大学 Boot-bus(启动总线)是cavium octeon处理器的一种用于启动系统的硬件. CPU通过boot b ...
- android之字体阴影效果
今天刚刚好做了个字体阴影的效果,感觉加上了阴影的效果立体感十足啊!写了个简单的demo与大家分享下!主要是以下四个属性 android:shadowColor 阴影的颜色 android:shad ...
- POJ 3254 Corn Fields (状态压缩DP)
题意:在由方格组成的矩形里面种草,相邻方格不能都种草,有障碍的地方不能种草,问有多少种种草方案(不种也算一种方案). 分析:方格边长范围只有12,用状态压缩dp好解决. 预处理:每一行的障碍用一个状态 ...
- FZU 1686 神龙的难题(DLX反复覆盖)
FZU 1686 神龙的难题 pid=1686" target="_blank" style="">题目链接 题意:中文题 思路:每个1看成列, ...