周赛-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 ...
随机推荐
- Python:操作文件
python操作文件库不需要安装其他module,文件操作类库是python语言自身支持的操作. 判定文件是否存在:os.path.isfile(filePath) import os import ...
- Lintcode: Kth Smallest Number in Sorted Matrix
Find the kth smallest number in at row and column sorted matrix. Example Given k = 4 and a matrix: [ ...
- 源码安装zabbix
源码安装zabbix 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 欢迎加入:高级运维工程师之路 598432640 前言:参考网上多篇源码安装的连接,自己把安装过程丢在这 ...
- demo04calc
package com.example.demo05simplecalc; import android.os.Bundle; import android.app.Activity; import ...
- JAVA中extends 与implements区别
JAVA中extends 与implements有啥区别?1. 在类的声明中,通过关键字extends来创建一个类的子类.一个类通过关键字implements声明自己使用一个或者多个接口.extend ...
- mongo聚合和mapreduce例子
聚合语句-比较集合内两字段大小 db.test.aggregate([ {$match:{"offlineTime":{$gt:ISODate("2016-09-13T0 ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON OverpaintRegion1
zw版[转发·台湾nvp系列Delphi例程]HALCON OverpaintRegion1 unit Unit1;interfaceuses Windows, Messages, SysUtils, ...
- 【Install】我是如何安装Linux类系统的
安装系统:ubuntu12.04 i386 DVD U盘启动12.04live系统 连线,设置连接 安装系统到硬盘 “语言支持”,更新 安装gnome经典界面 sudo apt-get i ...
- Inside TSQL Querying - Chapter 2. Physical Query Processing
Summary Description The SQL language is spoken by most database experts, and all relational database ...
- CSS 文字阴影(text-shadow)怎么用
textShadow="1px 1px 1px #ff0000" textShadow="水平位移 垂直位移 模糊半径 阴影颜色"