做$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函数的几个特殊点

    在ECMAScript中,Function(函数)类型实际上是对象.每个函数都是Function类型的实例,而且都与其他引用类型一样具有属性和方法.由于函数是对象,因此函数名实际上也是一个指向函数对象 ...

  2. windows 下的tcping 小插件

    如果把插件放在根目录 就要能过cmd切换到根目录 cd \ c:\>tcping -d -t -i 0.06 www.baidu.com 将文件放在c:\WINDOWS\system32目录下, ...

  3. Python 调试 PDB

    出处:http://blog.163.com/gjx0619@126/blog/static/12740839320114995947700/ 完整 请参考:http://docs.python.or ...

  4. Android N 新特性 + APP开发注意事项

    1. 多窗口MultiWindow 多窗口MultiWindow,这是Android N里对开发者影响比较大的特性,也是大家疑问比较多的地方.站在开发者的角度其实不必太担心这个特性会导致我们需要修改很 ...

  5. 【JAVA反射机制】

    一.Class类 Java.lang.Object |-java.lang.Class<T> 构造方法:无. 常用方法: static Class<?> forName(Str ...

  6. python中如何用dis模块来查看py的汇编代码?

    之前测试不成功,用导入dis的方式. 但如何在命令行里加入 -m dis,就会OK啦. python -m dis test.py #coding: utf8 x = [1, 2, 3] for i ...

  7. 无废话ExtJs 入门教程十三[上传图片:File]

    无废话ExtJs 入门教程十三[上传图片:File] extjs技术交流,欢迎加群(201926085) 1.代码如下: 1 <!DOCTYPE html PUBLIC "-//W3C ...

  8. 继续Get News List

    拿到news list 所需要的技能 json数组反序列化 iOS中有哪些集合对象 数组的遍历 Debugging with GDB json数组反序列化 id jsonObject = [NSJSO ...

  9. [读书笔记] Web 前端开发修炼之道

    原创地址:http://www.cnblogs.com/bnbqian/p/3735565.html 转载请注明出处 今天我们要读的书是Web 前端开发修炼之道 第1章 从网站重构说起 1.1 糟糕的 ...

  10. wp8 入门到精通 ---转换

             /// <summary>        /// 颜色字符串转Color        /// </summary>        public static ...