Longest Subsequence CodeForces - 632D (lcm)
大意: 给定序列$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)的更多相关文章
- 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 ...
- Educational Codeforces Round 9 D. Longest Subsequence dp
D. Longest Subsequence 题目连接: http://www.codeforces.com/contest/632/problem/D Description You are giv ...
- Educational Codeforces Round 9 D - Longest Subsequence
D - Longest Subsequence 思路:枚举lcm, 每个lcm的答案只能由他的因子获得,类似素数筛搞一下. #include<bits/stdc++.h> #define ...
- D. Longest Subsequence
D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- CF632D Longest Subsequence
D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 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 ...
- codeforces632D. Longest Subsequence (最小公倍数)
You are given array a with n elements and the number m. Consider some subsequence of a and the value ...
- Consecutive Subsequence CodeForces - 977F(dp)
Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把 ...
- [徐州网络赛]Longest subsequence
[徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...
随机推荐
- unittest详解(二) 跳过用例的执行(skip)
在执行测试用例时,有时候有些用例是不需要执行的,那我们怎么办呢?难道删除这些用例?那下次执行时如果又需要执行这些用例时,又把它补回来?这样操作就太麻烦了. unittest提供了一些跳过指定用例的方法 ...
- git介绍以及一些常用命令,加上vim编辑器的简单使用
https://www.jianshu.com/p/04a6517869b4 vim:进入vim编辑器,如果后接文件名,则进入该文件的编辑模式,看图:①.vim编辑器中,按i进入编辑模式:②.按Esc ...
- maven jdbc 驱动安装
https://mvnrepository.com/ 搜索 : com.microsoft.sqlserver 点击进入: https://mvnrepository.com/artifact/co ...
- 学习曲线(learning curves)
假定假设函数为一个二次函数,只是参数未定: 每给定一个样本大小,就能训练出对应的假设函数,从而利用这个假设函数可以计算出Jtrain(仍然在之前拿来训练的那些样本里面),然后将训练好的假设函数用在全部 ...
- Python中Counter统计数据输出具体办法
from collections import Counter # 列表 l_one = [1709020621, 1709020621, 1770603107, 1770603105, 177060 ...
- spark 笔记 1: 如何着手
必读:从官方的开发者页面着手,包括如何构建spark以及编码规范(强烈建议读读编程规范)等:https://cwiki.apache.org/confluence/display/SPARK/Cont ...
- java.net.BindException: Problem binding to [node2:45454] java.net.BindException: Cannot assign requested address
主要原因是网络的问题.可参考官方给出的详细解释. http://wiki.apache.org/hadoop/BindException 总之,这是网络或者配置网络的问题,跟 hadoop 基本没有关 ...
- orcal 根据打分时间计算打分情况
create or replace function F_GET_TEST(in_ny in date,in_project_id in number ) return number is sRetu ...
- OpenCV学习笔记(10)——图像梯度
学习图像梯度,图像边界等 梯度简单来说就是求导. OpenCV提供了三种不同的梯度滤波器,或者说高通滤波器:Sobel,Scharr和Lapacian.Sobel,Scharr其实就是求一阶或二阶导. ...
- Cross-Multimedia dataset
Wikipedia: http://www.svcl.ucsd.edu/projects/crossmodal/ PKU Xmedia: https://github.com/yeqinglee/mv ...