大意: 给定序列$a$, 求选出最长的一个子序列, 使得lcm不超过m.

刚开始想复杂了, 想着枚举gcd然后背包, 这样复杂度就是$O(\sum\limits_{i=1}^m \frac{m\sigma_0(i)}{i})$...... 估计了一下1e6大概只有1e8, 感觉剪个枝应该就可以过了, 打到最后才发现似乎不能输出方案...

看题解后发现就是个沙茶题, 直接枚举lcm即可.

#include <iostream>
#include <random>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endif int n, m, sum[N], a[N], f[N]; int main() {
scanf("%d%d", &n, &m);
REP(i,1,n) {
scanf("%d", a+i);
if (a[i]<=m) ++f[a[i]];
}
REP(i,1,m) if (f[i]) {
for (int j=i; j<=m; j+=i) sum[j]+=f[i];
}
int ans = 0, pos = 0;
REP(i,1,m) if (sum[i]>ans) ans=sum[i],pos=i;
if (!pos) return puts("1 0"),0;
printf("%d %d\n", pos, ans);
REP(i,1,n) if (pos%a[i]==0) printf("%d ", i);hr;
}

Longest Subsequence CodeForces - 632D (lcm)的更多相关文章

  1. Codeforces 632D Longest Subsequence 2016-09-28 21:29 37人阅读 评论(0) 收藏

    D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. Educational Codeforces Round 9 D. Longest Subsequence dp

    D. Longest Subsequence 题目连接: http://www.codeforces.com/contest/632/problem/D Description You are giv ...

  3. Educational Codeforces Round 9 D - Longest Subsequence

    D - Longest Subsequence 思路:枚举lcm, 每个lcm的答案只能由他的因子获得,类似素数筛搞一下. #include<bits/stdc++.h> #define ...

  4. D. Longest Subsequence

    D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  5. CF632D Longest Subsequence

    D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. D - Yet Another Problem On a Subsequence CodeForces - 1000D (DP,组合数学)

    D - Yet Another Problem On a Subsequence CodeForces - 1000D The sequence of integers a1,a2,-,aka1,a2 ...

  7. codeforces632D. Longest Subsequence (最小公倍数)

    You are given array a with n elements and the number m. Consider some subsequence of a and the value ...

  8. Consecutive Subsequence CodeForces - 977F(dp)

    Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把 ...

  9. [徐州网络赛]Longest subsequence

    [徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...

随机推荐

  1. vue路由 routers的写法:require用与不用

    vue路由的写法有很多种,这里我只说routers的写法,一种是compcomponent后面直接写路径,另一种是用require的方式,来看代码 import Vue from 'vue' impo ...

  2. windows 简单实用Elasticsearch

    官网下载地址:https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/zip/e ...

  3. 【转】diamond专题(二)– 核心原理介绍

    特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...

  4. bloom filter小结

    Bloom Filter是由 Howard Bloom在 1970 年提出的一种多哈希函数映射的快速查找算法,它是一种空间效率很高的随机数据结构,利用位数组很简洁地表示一个集合,并能判断一个元素是否属 ...

  5. 下载excle文件之工具

    创建万能的工具类,已备用 ExcelData.java 存放文件数据 package com.ulic.gis.dataCenter.util; import java.io.Serializable ...

  6. JavaScript中二进制与10进制互相转换

    webpack打包生成的代码中涉及了一些二进制位与的操作, 所以今天来学习一下JavaScript中的二进制与十进制转换操作吧 十进制转二进制: var num = 100 num.toString( ...

  7. 非GUI运行Jmeter,jtl文件没有响应数据的解决办法

    一.问题 Jmeter官方一直强调要在非GUI模式下运行Jmeter:Run your JMeter test in command-line non-GUI mode. 但在非GUI模式下运行生成的 ...

  8. 收货确定 BAPI BAPI_GOODSMVT_CREATE

    CLEAR gmhead.     gmhead-pstng_date = ls_table-gzdate."sy-datum .     gmhead-doc_date = sy-datu ...

  9. linux使用du查看文件夹大小

    du命令用来查看目录或文件所占用磁盘空间的大小.常用选项组合为:du –sh -s不显示该目录下面的文件大小,只显示该目录的大小 -h以人类可读的方式显示. 比如显示work下面的Apache-tom ...

  10. kendo Ui实现搜索选中建议 不改变输入框的值

    $("#SubjectFilter").kendoAutoComplete({ dataTextField: "patientCardNumber", temp ...