做$n$次递推求出$n$维Hash值即可,时间复杂度$O(nk)$。

#include<cstdio>
#define N 500010
int n,i,j,t,delta,ca,cb,a[10],b[10],c[N],d[N],p[N][10];
int seed[10]={233,13331,997,733,811,953,2011,1999,1997,1801};
unsigned int pow,target,f[11][N];
inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';}
int main(){
read(n);
for(i=0,ca=1;i<n;i++)read(a[i]),ca*=a[i];
for(i=0,cb=1;i<n;i++)read(b[i]),cb*=b[i];
for(i=0;i<ca;i++)read(c[i]);
for(i=0;i<cb;i++)read(d[i]);
for(i=0;i<cb;i++)for(t=i,j=n-1;~j;j--)p[i][j]=t%b[j],t/=b[j];
for(j=0;j<cb;j++)f[n][j]=d[j];
for(delta=1,i=n-1;~i;i--){
for(j=0;j<cb;j++){
f[i][j]=f[i+1][j];
if(p[j][i])f[i][j]+=f[i][j-delta]*seed[i];
}
delta*=b[i];
}
target=f[0][cb-1];
for(i=0;i<ca;i++)for(t=i,j=n-1;~j;j--)p[i][j]=t%a[j],t/=a[j];
for(j=0;j<ca;j++)f[n][j]=c[j];
for(delta=1,i=n-1;~i;i--){
for(pow=1,j=b[i];j;j--)pow*=seed[i];
for(j=0;j<ca;j++){
f[i][j]=f[i+1][j];
if(p[j][i])f[i][j]+=f[i][j-delta]*seed[i];
if(p[j][i]>=b[i])f[i][j]-=f[i+1][j-delta*b[i]]*pow;
}
delta*=a[i];
}
for(j=0;j<ca;j++){
for(t=1,i=0;i<n;i++)if(p[j][i]<b[i]-1){t=0;break;}
if(t&&f[0][j]==target){
for(i=0;i<n;i++)printf("%d ",p[j][i]-b[i]+2);
return 0;
}
}
}

  

BZOJ3740 : pku2842 N-dimension Matching N维匹配的更多相关文章

  1. 10. Regular Expression Matching[H]正则表达式匹配

    题目 Given an input string(s) and a pattern(p), implement regular expression matching with support for ...

  2. [leetcode]10. Regular Expression Matching正则表达式的匹配

    Given an input string (s) and a pattern (p), implement regular expression matching with support for  ...

  3. [leetcode]44. Wildcard Matching万能符匹配

    Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '? ...

  4. LeetCode OJ:Regular Expression Matching(正则表达式匹配)

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

  5. Regular Expression Matching,regex,正则表达式匹配,利用动态规划

    问题描述:Implement regular expression matching with support for '.' and '*'. '.' Matches any single char ...

  6. UVA 11019 二维匹配 AC自动机

    这个题目要求在一个大矩阵里面匹配一个小矩阵,是AC自动机的灵活应用 思路是逐行按普通AC自动机匹配,用过counts[i][j]记录一下T字符矩阵以i行j列为开头的与P等大的矩阵区域 有多少行已经匹配 ...

  7. 1023. Camelcase Matching驼峰式匹配

    网址:https://leetcode.com/problems/camelcase-matching/ 依题意可得逻辑 class Solution { public: vector<bool ...

  8. leetcode 44. Wildcard Matching(模糊匹配)

    搬运工了- - https://blog.csdn.net/jmspan/article/details/51460021

  9. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

随机推荐

  1. JS ——window.onload与$(document).ready()

    我们常常在页面加载完成以后做一些操作,比如一些元素的显示与隐藏.一些动画效果.我们通常有两种方法来完成这个事情,一个就是window.onload事件,另一个就是JQuery的ready()方法.那么 ...

  2. DB2 bind on z/os

    BIND and REBIND options for packages and plans There are several options you can use for binding or ...

  3. myeclipse 8.5 注册码

    刚才启动突然发现MyEclipse原来是收费的...汗一把,到弹出注册框我才知道.....老天啊我活的该有多窝囊.. 弹框很烦人,我一个穷书生既想继续学习又囊中羞涩无力购买,只好用盗版了(找个理由辩解 ...

  4. 一个简单的jsp+servlet实例,实现简单的登录

    开发环境myeclipse+tomcat6 1.先创建web project,项目名为RegisterSystem, 2.在WebRoot 目录下创建login.jsp文件,只需修改body中的内容, ...

  5. php 简易购物习题

    1.货物界面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...

  6. Vs 控件错位 右侧资源管理器文件夹点击也不管用,显示异常

    问题:显卡驱动异常. 缘由:驱动精灵万能显卡安装系统 解决方案:根据笔记本型号去官网下载适配显卡驱动.

  7. DHCP的若干原理解释

    转自:http://blog.chinaunix.net/uid-22287947-id-1775641.html 搜罗了几种关于dhcp的原理和过程解释 DHCP(Dynamic Host Conf ...

  8. C# 中的Singleton模式

    一般写Singleton基本都是一下这个套路 class Singleton { public static Singleton instance; private Singleton() { } p ...

  9. 重温WCF之数据契约中使用枚举(转载)(十一)

    转载地址:http://www.zhuli8.com/wcf/EnumMember.html 枚举类型的定义总是支持序列化的.当我们定义一个新的枚举时,不必应用DataContract特性,就可以在数 ...

  10. Delphi的面向对象编程基础笔记

    1.面向对象.一门面向对象的编程语言至少要实现以下三个OOP的概念 封装:把相关的数据和代码结合在一起,并隐藏细节.封装的好处是利用程序的模块化,并把代码和其他代码分开 继承:是指一个新的类能够从父类 ...