【CF1043D】Mysterious Crime(贡献)
2024-09-04 17:38:33
题意:给定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 ;
}
最新文章
- MySQL出错:ERROR 1045 (28000)的解决方法
- Python打包成exe程序
- LinuxShell脚本攻略--第三章 以文件之名
- 怎么用OCR图文识别软件在MS Office中创建PDF文件
- C#中Invoke和BeginInvoke的区别
- 【转】Rails 3.1错误-Could not find a JavaScript runtime及execjs和therubyracer介绍
- MySQL函数讲解(MySQL函数大全)
- [Mime] QuotedPrintableEncoding帮助类 (转载)
- java数组排序之冒泡排序
- JSON XML IO数据操作
- Spring学习使用标签来标记资源(@Component、@Repository、 @Service和@Controller)和用法(包括如何jsp正在使用)
- javaScript替换元素节点
- 多表insert操作详解
- 总结XSS与CSRF两种跨站攻击
- 微信小程序电商实战(-)商城首页
- 常见图片格式PNG,JPEG,BMP,GIF区别总结
- javascript重定向页面并用post方法传递消息
- Spring Boot + Spring Cloud 构建微服务系统(一):服务注册和发现(Consul)
- Introduction to Cryto &; Crptocurrencies Lecture 1
- python学习之内存机制
热门文章
- grep过滤目录或文件方法
- 1043: [HAOI2008]下落的圆盘
- 如何使用koa实现socket.io官网的例子
- Android系统中标准Intent的使用
- 关于js中onclick字符串传参问题(html=";";)
- 关于web.xml配置中的<;url-pattern>;
- python3 练习题100例 (十四)
- python学习——StringIO和BytesIO
- Paul Zindel【保罗&#183;金代尔】
- 【luminate primordial】苏州之行