Xyjj’s sequence
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int p=1e5+;
const int maxn=1e5+;
const int N=1e5+;
const int M=5e3+;
bool ok[maxn];
int prime[maxn],phi[maxn],cnt;
int a,b,n;
int u[N],v[N];
int dp[][M][];
//int dp[2*M][M][2];
void init()
{
phi[]=;
for(ll i=; i<maxn; ++i)
{
if(!ok[i])
{
prime[cnt++]=i;
phi[i]=i-;
}
for(int j=; j<cnt; ++j)
{
if(i*prime[j]>=maxn)break;
ok[i*prime[j]]=;
if(i%prime[j]==)
{
phi[i*prime[j]]=phi[i]*prime[j];//prime[j]是i的因子 prime[j]的素因子项包含在i的素因子项里
break;
}
else phi[i*prime[j]]=phi[i]*(prime[j]-);//prime[j]与i互质 phi[i*prime[j]=phi[i]*phi[prime[j]]
}
}
}
int modpow(int x,int n,int mod)
{
int ans=;
for(; n; n/=,x=1ll*x*x%mod)
if(n&)ans=1ll*ans*x%mod;
return ans;
}
int f(int num,int mod)
{
if(mod==)return ;
if(num==)return b%mod;
return modpow(b,f(num-,phi[mod])+phi[mod],mod);
}
int main()
{
init();
while(scanf("%d%d",&a,&b)!=EOF)
{
scanf("%d",&n);
for(int i=; i<=n; ++i)
{
scanf("%d",&u[i]);
u[i]=modpow(a,f(u[i],phi[p])+phi[p],p);
}
for(int i=; i<=n; ++i)
{
scanf("%d",&v[i]);
v[i]=modpow(a,f(v[i],phi[p])+phi[p],p);
}
memset(dp,,sizeof dp);
u[]=v[]=p+;//保证和第二项不同 /**for(int j=1;j<=n;j++){
for(int i=j;i<=n+j;i++){
dp[i][j][0]=max(dp[i-1][j-1][0]+u[j]*(u[j-1]==u[j]),dp[i-1][j-1][1]+u[j]*(v[j-1]==u[j]));
dp[i][j][1]=max(dp[i-1][j-1][1]+v[j]*(v[j-1]==v[j]),dp[i-1][j-1][0]+v[j]*(u[j-1]==v[j]));
}
}*/
for(int k=; k<=n; ++k)
{
int i=k&;
//cout<<i<<" "<<(i^1)<<'\n';
for(int j=; j<=n; ++j)
{
dp[i][j][]=;
dp[i][j][]=;
}
///滚动 ///u取第k位
///v取第j位
///如何保证无后效性??
for(int j=; j<=n; ++j)
{
if(k>)
{
dp[i][j][]=max(dp[i][j][],dp[i^][j][]+u[k]*(u[k]==u[k-]));///u[k]的前一位可以是u[k-1]
dp[i][j][]=max(dp[i][j][],dp[i^][j][]+u[k]*(u[k]==v[j]));///u[k]前一位可以是v的任一位
}
if(j>)
{
dp[i][j][]=max(dp[i][j][],dp[i][j-][]+v[j]*(v[j]==u[k]));///v[j]的前一位可以是u的任一位
dp[i][j][]=max(dp[i][j][],dp[i][j-][]+v[j]*(v[j]==v[j-]));///v[j]的前一位可以是v[j-1]
}
} }
printf("%d\n",max(dp[n&][n][],dp[n&][n][]));
}
return ;
}
Xyjj’s sequence的更多相关文章
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
随机推荐
- linux/linux学习笔记-vim文本编辑器(mooc)
vim文本编辑器 vim与vi的区别:( vim=vi +IMproved) VIM是一个Unix以及类unix文本编辑器 特点:功能强大,高度可定制 vim编辑器的三种模式:一般模式.编辑模式和命令 ...
- vue组件注册(极客时间Vue视频笔记)
vue组件注册 组件是为了方便代码复用,只需引入组件即可在不同的地方使用想同的功能代码 <body> <div class="app"> <todo- ...
- SpringBoot项目启动时执行初始化操作
SpringBooot中的CommandLineRunner接口会在所有Spring Beans初始化之后,SpringApplication.run()之前执行. 1.添加pom引用 <?xm ...
- [Web 前端] 023 js 的流程控制、循环和元素的获取、操作
1. Javascript 流程控制 用于"基于不同条件执行不同的动作"的场合 1.1 if 语句 三种形式 // 第一种 if... // 第二种 if... else ... ...
- [ARC101E]Ribbons on Tree(容斥,dp)
Description 给定一棵有 \(n\) 个节点的树,满足 \(n\) 为偶数.初始时,每条边都为白色. 现在请你将这些点两两配对成 \(\frac{n}{2}\) 个无序点对.每个点对之间的的 ...
- Requests的基本使用
Requests库 r=requests.get(url) #返回一个包含服务器资源的Response对象 #构造一个向服务器请求资源的Request对象 格式:requests.get(url,pa ...
- Ubuntu终端路径和文件夹相互切换
一. 环境配置 1. 打开终端输入安装命令 sudo apt-get install nautilus-open-terminal 2. 重新加载文件管理器 nautilus -q 3. 重启电脑 s ...
- Python数据基础类型-新建列表
1,遍历列表 遍历列表的所有元素,对每个元素执行相同的操作.可使用for循环 magicians = ['alice','david','carolina'] for magician in magi ...
- P4556 [Vani有约会]雨天的尾巴(线段树合并+lca)
P4556 [Vani有约会]雨天的尾巴 每个操作拆成4个进行树上差分,动态开点线段树维护每个点的操作. 离线处理完向上合并就好了 luogu倍增lca被卡了5分.....于是用rmq维护.... 常 ...
- linux下解压缩.tar.bz2到某目录下
1\可先进入要解压的目的目录,然后使用tar命令 比如我要将桌面的a.tar.bz2解压到/var/b cd /var/b tar -xjf /root/Desktop/a.tar.bz2 ...