https://vjudge.net/contest/386568#problem/E

Sometimes, changing the order of the words in a sentence doesn't influence understanding. For example, if we change "what time is it", into "what time it is"; or change "orz zhang three ak world final", into "zhang orz three world ak final", the meaning of the whole sentence doesn't change a lot, and most people can also understand the changed sentences well.

Formally, we define a sentence as a sequence of words. Two sentences SS and TT are almost-equal if the two conditions holds:

1. The multiset of the words in SS is the same as the multiset of the words in TT.
2. For a word αα, its ithith occurrence in SS and its ithith occurrence in TT have indexes differing no more than 11. (The kthkth word in the sentence has index kk.) This holds for all αα and ii, as long as the word αα appears at least ii times in both sentences.

Please notice that "almost-equal" is not a equivalence relation, unlike its name. That is, if sentences AA and BB are almost-equal, BB and CC are almost-equal, it is possible that AA and CC are not almost-equal.

Zhang3 has a sentence SS consisting of nn words. She wants to know how many different sentences there are, which are almost-equal to SS, including SS itself. Two sentences are considered different, if and only if there is a number ii such that the ithith word in the two sentences are different. As the answer can be very large, please help her calculate the answer modulo 109+7109+7.

InputThe first line of the input gives the number of test cases, T(1≤T≤100)T(1≤T≤100). TT test cases follow.

For each test case, the first line contains an integer n(1≤n≤105)n(1≤n≤105), the number of words in the sentence.

The second line contains the sentence SS consisting of nn words separated by spaces. Each word consists of no more than 1010 lowercase English letters.

The sum of nn in all test cases doesn't exceed 2×1052×105.
OutputFor each test case, print a line with an integer, representing the answer, modulo 109+7109+7.
Sample Input

2
6
he he zhou is watching you
13
yi yi si wu yi si yi jiu yi jiu ba yao ling

Sample Output

8
233

题意:

  给定串S,包含n个单词,求相似的句子T的个数(包含自己

  相似的两个条件:

    单词的多重集是一样的 多重集单词T

    词α 出现在S第i个词和在T中出现第i个词的索引相差不超过1。(句子中的第K单词索引为K)

      (这适用于所有单词α,只要这个词α至少两次出现在这两个句子

思路:

  计算一个数列

  这个数列记录前 i 个单词组成的相似字符串的个数

  如果有相同单词在相邻位置,则交换后不产生影响;
  如果相同的单词交换,产生前两种之和

  一直到所有完成。

代码:

  数字太大注意取模

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
//#define sort(a,n,int) sort(a,a+n,less<int>()) #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db; const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;
const int N=2e5+10;
const int mod=1e9+7; int sum[100005] = {0};
string s[100005];
int main()
{
int T = 0;
int n = 0;
cin >> T;
while(T--)
{
cin >> n;
memset(sum , 0 , sizeof(sum));
sum[0] = sum[1] = 1;
for(int i = 1;i<=n;i++)
{
cin >> s[i];
}
for(int i = 2;i<=n;i++)
{
if(s[i] == s[i-1])
{
sum[i] = sum[i-1];
}
else
{
sum[i] = (sum[i-2] + sum[i-1]);
sum[i] %= mod;
}
}
cout << sum[n] <<endl;
}
return 0;
}

  

E - Equal Sentences的更多相关文章

  1. hdu 6806 Equal Sentences 找规律

    题意: 给你一个有n个单词的单词串S,对这n个单词进行排列组合形成新的一个单词串T,如果在S中任意某个单词所在位置,和这个单词在T中所在位置之差的绝对值小于等于1,那么就说S和T串相等 让你求S一共有 ...

  2. [LeetCode] Minimum Moves to Equal Array Elements II 最少移动次数使数组元素相等之二

    Given a non-empty integer array, find the minimum number of moves required to make all array element ...

  3. [LeetCode] Minimum Moves to Equal Array Elements 最少移动次数使数组元素相等

    Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...

  4. [LeetCode] Partition Equal Subset Sum 相同子集和分割

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  5. Equal Sides Of An Array

    参考:http://stackoverflow.com/questions/34584416/nested-loops-with-arrays You are going to be given an ...

  6. Int,Long比较重使用equal替换==

    首先,==有很多限制,如Integer 类型的值在[-128,127] 期间,Integer 用 “==”是可以的(参考),超过范围则不行,那么使用equal则代替则完全ok public stati ...

  7. 无法解决 equal to 操作中 "SQL_Latin1_General_CP1_CI_AS" 和 "Chinese_PRC_CI_AS"

    无法解决 equal to 操作中 "SQL_Latin1_General_CP1_CI_AS" 和 "Chinese_PRC_CI_AS" 之间 2011-0 ...

  8. LeetCode Minimum Moves to Equal Array Elements II

    原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ 题目: Given a non-empt ...

  9. LeetCode Minimum Moves to Equal Array Elements

    原题链接在这里:https://leetcode.com/problems/minimum-moves-to-equal-array-elements/ 题目: Given a non-empty i ...

  10. conflict between "Chinese_PRC_CI_AI" and "Chinese_PRC_CI_AS" in the equal to operation

    在SQL SERVICE做关联查询的时候遇到了"conflict between "Chinese_PRC_CI_AI" and "Chinese_PRC_CI ...

随机推荐

  1. 上传自己java项目到maven中央仓库pom

    前提 首先的你项目需要在Gitee或者Github上有仓库 我这里以Gitee是的yhchat-sdk-core仓库为例 开始 在sonatype上创建问题 访问sonatype注册并登录 创建一个问 ...

  2. 对apache服务器环境下利用.htaccess配置文件完成文件上传的理解

    对apache服务器环境下利用.htaccess配置文件完成文件上传的理解 .htaccess 文件是 Apache Web 服务器中的配置文件,用于控制服务器的行为.其格式非常简单,通常由一系列指令 ...

  3. 主流负载均衡器LVS、Nginx、HAProxy介绍

    一.简单介绍 1.1 LVS LVS是Linux Virtual Server的缩写,意思是Linux虚拟服务器,LVS由用户空间的ipvsadm和内核空间的ipvs组成,ipvsadm用来定义规则, ...

  4. 树结构Tree

    树结构 平衡顺序二叉树 通过平衡顺序二叉树查数据的时候,也就等同于二分查找的操作 Binary Search 2,3树 二三树 二三树有 node2 和 node3 两种节点,树的规则如图 2-3-4 ...

  5. 基于开源大数据调度系统Taier的Web前端架构选型及技术实践

    原文链接:基于开源大数据调度系统Taier的Web前端架构选型及技术实践 课件获取:关注公众号"数栈研习社",后台私信"Taier"获得直播课件 视频回放:点击 ...

  6. Java源码分析系列笔记-9.CountDownLatch

    目录 1. 是什么 2. 如何使用 2.1. CountDownLatch VS CyclicBarrier 3. uml 4. 构造方法 4.1. Sync[AQS子类] 5. countDown方 ...

  7. 【公开课】芯片ATE测试—93K机台与Smartest软件介绍

    当前,随着中国集成电路产业的高速发展,芯片测试作为确保产品良率与可靠性的关键环节,其技术人才缺口日益凸显.尤其在测试设备操作层面,行业普遍面临两大痛点: 一方面,高端ATE测试平台(如93K系统)操作 ...

  8. poi 酱放过的每日一歌

    整理一下 poi 酱放过的每日一歌,大概按照时间排序,如果有喜欢的大家可以参考一下. poi 酱喜欢什么样的歌 基本上从 \(2 \times 2\) 个维度考虑:唱腔(甜度.软度)和歌词(内容.与曲 ...

  9. 【闲话 No.2】 长链剖分

    壱雫空 本来打算省选游记推这首歌的,但是省选破大防了,最后他来到了这里.感觉拿这个当起床铃效果一定很好(关键这歌超好听的!). もしこの雨が上がっても 忘れずに歩いてくよ 最初のひとしずくに 顔上げた ...

  10. visual studio 推送项目上自己的github账户报错

    https://blog.csdn.net/weixin_43129574/article/details/104753639?utm_medium=distribute.pc_aggpage_sea ...