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 ...
随机推荐
- php正则表达式的学习
真的发现什么都需要这个 所以还是来把它学了吧 正则表达式的基本知识汇总 行定位符(^与$) 行定位符是用来描述字符串的边界.“$”表示行结尾“^”表示行开始如"^de",表示以de ...
- 并发编程--Concurrent-工具类介绍
并发编程--Concurrent-工具类介绍 并发编程--Concurrent-工具类介绍 CountDownLatch CylicBarrier Semaphore Condition 对象监视器下 ...
- 套接字之recvfrom系统调用
recvfrom系统调用通过用户传入的接收空间构造msghdr,并且调用sock_recvmsg,该函数调用socket操作的recvmsg函数sock->ops->recvmsg,ipv ...
- How to correctly use preventDefault(), stopPropagation(), or return false; on events
How to correctly use preventDefault(), stopPropagation(), or return false; on events I’m sure this h ...
- spark 笔记 1: 如何着手
必读:从官方的开发者页面着手,包括如何构建spark以及编码规范(强烈建议读读编程规范)等:https://cwiki.apache.org/confluence/display/SPARK/Cont ...
- DPM(物体检测)
1.DPM(物体检测流程) 1.计算DPM特征图 2.计算响应图 3.使用SVM对响应图进行分类 4.对最后的选框做局部检测识别 DPM的梯度提取方向,将图片中的四个区域进行区分,将有符号梯度方向从0 ...
- Selenium 2自动化测试实战8(控制浏览器)
一.控制浏览器 1. 控制浏览器窗口大小 webdriver提供了set_window_size()方法来设置浏览器的大小 #test.py #coding:utf-8 from selenium i ...
- Nginx负载均衡服务器实现会话粘贴的几种方式
1. 使用Nginx 的ip_hash作为负载均衡服务并支持Session sticky 2. 使用nginx sticky第三方模块实现基于cookie的负载均衡 3.使用nginx的map指令根据 ...
- Python学习之==>数组(一)
1.定义数组 city = [] # 定义一个空数组 name = ['Jack','Panda','Bob','Franck'] # 根据下标找元素,最前面一个元素的下标是0,最后一个元素下标是-1 ...
- harbor仓库安装
https://6xyun.cn/article/50 环境: 192.168.0.65 harbor .docker 一.安装相关依赖 .安装Docker Docker 使用离线版docker-ce ...