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 ...
随机推荐
- nopCommerce4.10学习笔记——入门
1.下载 千万不要去GitHub上下载,千万不要去GitHub上下载,千万不要去GitHub上下载!!!,重要的事情说3遍,说多了都是泪,你懂的 下载网址:https://www.nopcommerc ...
- DVWA--Brute Force
这次我们尝试的内容是DVWA的暴力破解 --lower 先抓取一个登陆的包 然后发送到后在Position选项中设置需要破解的变量.Burpsuite会自动设置许多变量,单击“Clear”按钮,把默认 ...
- C++入门经典-例2.7-控制cout打印格式程序
1:代码如下: // 2.7.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #incl ...
- 如何把java项目打包成war包
用Eclipse手动打包 右击工程名 选择Export… 选择Web → WAR file 点击Browse,选择导出路径 然后war包就被导出来啦~是不是很简单呢 利用Maven的package命令 ...
- 【nginx】 配置域名转发到相同地址不同端口下执行相应业务
#doctor upstream doc { server 52.**.**.***:8090; } #patient upstream pat { server 52.**.**.***:8088; ...
- python3笔记十二:python数据类型-Dictionary字典
一:学习内容 字典概念 字典创建 字典访问 字典添加 字典删除 字典遍历 字典与列表比较 二:字典概念 1.使用键值对(key-value)存储,具有极快的查找速度 2.注意:字典是无序的 3.特性: ...
- 使用FFmpeg让mp4转gif
配好环境之后,需要在开始菜单中打开命令提示符,然后进入到test.mp4的文件目录下执行命令.(直接在文件目录下打开cmd不能生效)ffmpeg -i test.mp4 -f gif test.gif
- Vagrant基本命令详解
正在学习Docker Swarm,接触到了Vagrant.Vagrant是一个创建虚拟机的技术,可以把它认为是一个Vmware,它让我们可以通过代码的方式快速地.可重复地创建针对不同虚拟环境的虚拟机, ...
- luoguP1502过河题解
日常吐(fei)嘈(hua) 这道题作为最近卡了我3天的dp题(最后还是在题解的帮助下冥思苦想才过掉的题),窝觉得此题肥肠之脑洞,写此博客纪念 题解 过河 先来日常手玩样例: 咦感觉怎么手玩答案都像是 ...
- 【剑指offer37】二叉树的序列化
序列化过程很简单,如果是采用先序序列,那么对先序遍历做出改变即可: 层序遍历建立二叉树,如: 1 2 3 4 # 5 6 输入第一行:将要输入的节点的个数N,如上面的为7 ...