题意:给定m个人,每个人有n个数字且每个人的所有数字都是一个n的排列,求有多少种方案去掉某个前缀和后缀后m个人剩余的部分相等

m<=10,n<=1e5

思路:考虑极长的一段连续匹配的串,因为最后需要是连续的一段,所以它对答案的贡献应该是它的子串个数

刚开始以为是子序列个数还傻乎乎的去写高精了,也算是一个教训吧

 #include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 110000
#define M 130
#define MOD 1000000007
#define eps 1e-8
#define pi acos(-1) int a[][N],b[][N],n,m; int isok(int x,int y)
{
//if(x==0) return 1;
for(int i=;i<=m;i++)
if(b[i][x]!=b[i][y]-) return ;
return ;
} int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
for(int j=;j<=n;j++)
{
scanf("%d",&a[i][j]);
b[i][a[i][j]]=j;
}
a[][]=;
ll ans=;
ll len=;
for(int i=;i<=n;i++)
if(isok(a[][i-],a[][i])) len++;
else
{
//printf("len=%lld\n",len);
ans+=(len+)*len/;
len=;
}
//printf("len=%lld\n",len);
ans+=(len+)*len/; printf("%lld\n",ans);
return ;
}

最新文章

  1. MySQL出错:ERROR 1045 (28000)的解决方法
  2. Python打包成exe程序
  3. LinuxShell脚本攻略--第三章 以文件之名
  4. 怎么用OCR图文识别软件在MS Office中创建PDF文件
  5. C#中Invoke和BeginInvoke的区别
  6. 【转】Rails 3.1错误-Could not find a JavaScript runtime及execjs和therubyracer介绍
  7. MySQL函数讲解(MySQL函数大全)
  8. [Mime] QuotedPrintableEncoding帮助类 (转载)
  9. java数组排序之冒泡排序
  10. JSON XML IO数据操作
  11. Spring学习使用标签来标记资源(@Component、@Repository、 @Service和@Controller)和用法(包括如何jsp正在使用)
  12. javaScript替换元素节点
  13. 多表insert操作详解
  14. 总结XSS与CSRF两种跨站攻击
  15. 微信小程序电商实战(-)商城首页
  16. 常见图片格式PNG,JPEG,BMP,GIF区别总结
  17. javascript重定向页面并用post方法传递消息
  18. Spring Boot + Spring Cloud 构建微服务系统(一):服务注册和发现(Consul)
  19. Introduction to Cryto &amp; Crptocurrencies Lecture 1
  20. python学习之内存机制

热门文章

  1. grep过滤目录或文件方法
  2. 1043: [HAOI2008]下落的圆盘
  3. 如何使用koa实现socket.io官网的例子
  4. Android系统中标准Intent的使用
  5. 关于js中onclick字符串传参问题(html=&quot;&quot;)
  6. 关于web.xml配置中的&lt;url-pattern&gt;
  7. python3 练习题100例 (十四)
  8. python学习——StringIO和BytesIO
  9. Paul Zindel【保罗&#183;金代尔】
  10. 【luminate primordial】苏州之行