周赛-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
inputstandard input
outputstandard output
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.
Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.
Let’s define a divisibility graph for a set of positive integers A = {a1, a2, …, an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i ≠ j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.
You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A.
Input
The first line contains integer n (1 ≤ n ≤ 106), that sets the size of set A.
The second line contains n distinct positive integers a1, a2, …, an (1 ≤ ai ≤ 106) — elements of subset A. The numbers in the line follow in the ascending order.
Output
Print a single number — the maximum size of a clique in a divisibility graph for set A.
Sample test(s)
input
8
3 4 6 8 10 18 21 24
output
3
Note
In the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn’t exist in this graph.
类似求最大最大上升子序列;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <list>
#include <algorithm>
#define PI acos(-1.0)
#define RR freopen("input.txt","r",stdin)
#define WW freopen("output.txt","w",stdout)
using namespace std;
const int MOD = (int)1e9+10;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const int MAX = 1e6+10;
int Dp[MAX];
int a[MAX];
int main()
{
int n,i,j,sum;
while(scanf("%d",&n)!=EOF)
{
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
sum=0;
for(i=n-1; i>=0; i--)
{
Dp[a[i]]=1;
for( j=2; a[i]*j<MAX; j++)
{
Dp[a[i]]=max(Dp[a[i]],Dp[a[i]*j]+1);//Dp[a[i]*j]记录的是以它为开头的子序列的最大长度
}
sum=max(sum,Dp[a[i]]);//找到最大的子序列
}
printf("%d\n",sum);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
周赛-Clique in the Divisibility Graph 分类: 比赛 2015-08-02 09:02 23人阅读 评论(3) 收藏的更多相关文章
- Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- iOS开源库--最全的整理 分类: ios相关 2015-04-08 09:20 486人阅读 评论(0) 收藏
youtube下载神器:https://github.com/rg3/youtube-dl 我擦咧 vim插件:https://github.com/Valloric/YouCompleteMe vi ...
- Jquery easy UI 上中下三栏布局 分类: ASP.NET 2015-02-06 09:19 368人阅读 评论(0) 收藏
效果图: 源代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- JqueryEasyUI 解决IE下加载时页面错乱的问题 分类: JavaScript JqueryEasyUI 2014-09-20 09:50 545人阅读 评论(1) 收藏
问题描述: 一直觉得jqueryeasyui在IE下的渲染效果不大好,尤其刚进入页面时的加载,页面会出现布局错乱,虽然是一闪而过,但是给用户的体验不好: 可以通过在页面onload时,增加一个遮罩层, ...
- C# IIS应用程序池辅助类 分类: C# Helper 2014-07-19 09:50 249人阅读 评论(0) 收藏
using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using Microsoft ...
- PIGS 分类: POJ 图论 2015-08-10 09:15 3人阅读 评论(0) 收藏
PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18209 Accepted: 8277 Description Mir ...
- Babelfish 分类: 哈希 2015-08-04 09:25 2人阅读 评论(0) 收藏
Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36398 Accepted: 15554 Descripti ...
- java 解决JFrame不能设置背景色的问题 分类: Java Game 2014-08-15 09:48 119人阅读 评论(0) 收藏
这段时间比较多,于是写一写JAVA的一些IT技术文章.如有JAVA高手请加QQ:314783246,互相讨论. 在Java的GUI设计中,Frame和JFrame两者之间有很大差别,上次刚学时编一个窗 ...
- Poj 2528 Mayor's posters 分类: Brush Mode 2014-07-23 09:12 84人阅读 评论(0) 收藏
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40570 Accepted: 11798 ...
- Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9557 Accepted: 3187 De ...
随机推荐
- String类型方法
String类型 //1.返回长度 length var a="lynn_hello"; console.log(a.length); //2.相加 concat() 返回一个新的 ...
- Lintcode: Majority Number III
Given an array of integers and a number k, the majority number is the number that occurs more than 1 ...
- 传递闭包(Floyd+bellman-Fold POJ1932)
传递闭包 在一个有向(无向)连通图中,如果节点i与k联通,k与j联通,则i和j联通,传递闭包就是把所有传递性的节点求出来,之后就知道了任意两个节点的连通性,只需枚举节点的联通情况即可,无需考虑最短路径 ...
- fzu 2188 过河I
http://acm.fzu.edu.cn/problem.php?pid=2188 过河I Time Limit:3000MS Memory Limit:32768KB 64bit ...
- .NET: C#: 获取当前路径
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...
- scrum站立会议------10.20
小组名称:nice! 小组成员:李权 于淼 杨柳 刘芳芳 项目内容:约跑app(约吧--暂定) 1.任务进度 2.燃尽图
- 【转】SQL Server T-SQL高级查询
SQL Server T-SQL高级查询 高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student; //查询student ...
- dota玩家与英雄契合度的计算器,python语言scrapy爬虫的使用
首发:个人博客,更新&纠错&回复 演示地址在这里,代码在这里. 一个dota玩家与英雄契合度的计算器(查看效果),包括两部分代码: 1.python的scrapy爬虫,总体思路是pag ...
- android 学习随笔三(测试与单元测试框架)
测试 1.按岗位: 黑盒测试:测试业务逻辑 白盒测试:测试逻辑方法 2.按测试粒度 方法测试 function 单元测试 unit 集成测试 integration 系统测试 system 3.按暴力 ...
- Thinking In Java 读书笔记
面向对象语言,五个基本特性: 1)万物皆为对象. 2)程序是对象的集合,他们通过发送消息来告知彼此所要做的. 3)每个对象都有自己的由其他对象所构成的存储. 4)每个对象都拥有其类型.即:每个对象都是 ...