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 ...
随机推荐
- RPM包或源码包
安装RPM包或源码包 点击vmware右下角光驱连接. 安装rpm包 -i:表示安装 -v:表示可视化 -h:表示显示安装进度 (同时使用) --force:表示强制安装,即使覆盖属于其他包的文件也要 ...
- gcc 消除未使用变量的警告
我们写代码的时候经常需要遇到一些情况,参数暂时没用到.但是这个参数必须存在. 例如linux下线程实体函数void *thread_xx(void *arg)如果不处理,gcc编译时就会报" ...
- Eclipse连接SQL Server 2008数据库
一.准备材料 要能够使用数据库就要有相应的JDBC,所以我们要去Microsoft官网下载 https://www.microsoft.com/zh-cn/download/details.aspx? ...
- 《剑指offer》面试题25 二叉树中和为某一值的路径 Java版
(判断是否有从根到叶子节点的路径,其和为给定值.记录这些路径.) 我的方法:这道题我是按照回溯的思路去做的,我们需要一个数据结构来保存和删除当前递归函数中添加的值.这里要打印一条路径,我们可以选择Li ...
- mybatis oracle 批量新增
假定场景:批量导入用户信息 一般批量新增使用 SELECT … INSERT INTO 和 INSERT INTO … SELECT 我们这次使用第二种 一.先建一张用户信息表模拟批量导入用户信息 c ...
- 说说无线路由器后门的那些事儿(1)-D-Link篇
[原创]说说无线路由器后门的那些事儿(1)-D-Link篇 作 者: gamehacker 时 间: 2013-11-29,11:29:19 链 接: http://bbs.pediy.com/sho ...
- Python 自定义三方库
一.注册一个pypi账号 https://pypi.org/ 二.github上创建一个项目 https://github.com/ 三.编写自己的python项目 项目结构(参考):https:// ...
- vector auto
#include <iostream>#include <vector>#include <string>using namespace std;using std ...
- 通过spring工具类获取bean
package xxx; import org.springframework.beans.BeansException; import org.springframework.beans.facto ...
- 微信 PHP - SDK 包
下载 个人公众号谢谢各位老铁支持