在这里插入图片描述

#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int P = 1e9 + 7;
const int maxn = 2e5 + 20;

string str[maxn];
bool v[maxn];
int n, ans;
ll dp[maxn];

inline string read()
{
 char ch = getchar();
 string st1 = "";
 while (!((ch >= 'a') && (ch <= 'z')))
  ch = getchar();
 while ((ch >= 'a') && (ch <= 'z'))
  st1 += ch, ch = getchar();
 return st1;
}

int main()
{
 int t;
 scanf("%d", &t);
 while (t--)
 {
  scanf("%d", &n);
  ans = 0;
  for (int i = 1; i <= n; i++)
  {
   str[i] = read();
   v[i] = 1;
  }
  for (int i = 1; i < n; i++)
   if (str[i] == str[i + 1])
    v[i] = 0;
  memset(dp, 0, sizeof(ll) * (n + 5));
  dp[0] = 0, dp[1] = 0;
  for (int i = 2; i <= n; i++)
  {
   if (v[i - 1] == 0)
    dp[i] = dp[i - 1] % P;
   else
    dp[i] = (dp[i - 1] % P + dp[i - 2] % P + 1) % P;
  }
  printf("%lld\n", dp[n] % P + 1);
 }
}
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐