做$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. hdu 1005

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 思路:找规律题 #include<stdio.h> main() { ]; int ...

  2. 使用Autofac在ASP.NET Web API上实现依赖注入

    在ASP.NET Web API里使用Autofac 1.通过NuGet安装Autofac.WebApi(当时安装的是Autofac 3.1.0) PM > Install-Package Au ...

  3. SQL中的多表查询,以及JOIN的顺序重要么?

    说法是,一般来说,JOIN的顺序不重要,除非你要自己定制driving table. 示例: SELECT a.account_id, c.fed_id, e.fname, e.lname -> ...

  4. js继承的概念

    js里常用的如下两种继承方式: 原型链继承(对象间的继承) 类式继承(构造函数间的继承) 由于js不像java那样是真正面向对象的语言,js是基于对象的,它没有类的概念.所以,要想实现继承,可以用js ...

  5. android 入门-控件 测量状态栏高度

    private ViewTreeObserver viewTreeObserver; /** 获取可見区域高度 **/ WindowManager manager = getWindowManager ...

  6. Win10 UAP 绑定

    Compiled DataBinding in Windows Universal Applications (UAP) http://nicksnettravels.builttoroam.com/ ...

  7. 提高WPF程序性能的几条建议

    这篇博客将介绍一些提高WPF程序的建议(水平有限,如果建议有误,请指正.) 1. 加快WPF程序的启动速度: (1).减少需要显示的元素数量,去除不需要或者冗余的XAML元素代码. (2).使用UI虚 ...

  8. 用.NET开发通用Windows App

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:随着Windows 10的正式发布,作为.NET开发人员应该开始或多或少了解一下通用( ...

  9. GitHub 使用教程图文详解(转)

    大纲: 一.前言 二.GitHub简介 三.注册GitHub账号 四.配置GitHub 五.使用GitHub 六.参与GitHub中其它开源项目 七.总结 注,GitHub官网:https://git ...

  10. github 使用网址

    [Github教程]史上最全github使用方法:github入门到精通 http://blog.csdn.net/hcbbt/article/details/11651229 githup的使用 h ...