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 ...
随机推荐
- Python-自定义函数-参数
一.自定义函数参数 1.种类 (1)位置参数 "x"就是位置参数 #!/usr/bin/env python # -*- coding: utf-8 -*- #author: di ...
- 使用 PC 做 FTP/TFTP 服务器,上传和下载文件
使用PC做TFTP服务器,上传和下载文件需要用到一个工具软件,IPOP,可百度下载. 1.在桌面新建一个空闲的文件夹,作为TFTP服务器的存储位置,然后打开IPOP软件,开启服务. 图片中 编号3 的 ...
- 使用Object.create()实现继承 用 Object.create实现类式继承
使用Object.create()实现继承:https://www.cnblogs.com/cuew1987/p/4075027.html 用 Object.create实现类式继承:https:// ...
- java字符流读取文件
package ba; import java.io.*; public class zifuTest { public static void main(String[] args) { FileI ...
- 【问题解决方案】git仓库重构
Linux mv命令 用来为文件或目录改名.或将文件或目录移入其它位置. 语法 mv [options] source dest mv [options] source... directory 注: ...
- MySQL之表查询
语法执行顺序 from >>>从那张表 where >>> 全局的筛选条件 group by>>> 必须是用在where 之后一组就是为了接下来我 ...
- Educational Codeforces Round 68 (Rated for Div. 2) D. 1-2-K Game (博弈, sg函数,规律)
D. 1-2-K Game time limit per test2 seconds memory limit per test256 megabytes inputstandard input ou ...
- sshfs 挂载远程文件夹
1 安装 # yum install sshfs # dnf + releases] $ sudo apt-get install sshfs [On Debian/Ubuntu based syst ...
- python3-安装第三方模块
在Python中,安装第三方模块,是通过包管理工具pip完成的. 如果你正在使用Mac或Linux,安装pip本身这个步骤就可以跳过了. 如果你正在使用Windows,请参考安装Python一节的内容 ...
- Laravel——缓存使用
1.使用Redis类 use Illuminate\Support\Facades\Redis; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...