• Reversi


    题目描述:

    There are N stones arranged in a row. The i-th stone from the left is painted in the color Ci.
    Snuke will perform the following operation zero or more times:
    Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.
    Find the number of possible final sequences of colors of the stones, modulo 109+7.

    Constraints
    ·1≤N≤2×105
    ·1≤Ci≤2×105(1≤i≤N)
    ·All values in input are integers.

    输入

    Input is given from Standard Input in the following format:

    N
    C1
    :
    CN

    输出

    Print the number of possible final sequences of colors of the stones, modulo 109+7.

    样例输入

    5
    1
    2
    1
    2
    2

    样例输出

    3

    提示

    We can make three sequences of colors of stones, as follows:
    ·(1,2,1,2,2), by doing nothing.
    ·(1,1,1,2,2), by choosing the first and third stones to perform the operation.
    ·(1,2,2,2,2), by choosing the second and fourth stones to perform the operation.

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const ll N=200200;
    const ll p=1e9+7;
     
    ll a[N],n,b[N],f[N];
    int main() {
      scanf("%lld", &n);
      for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
      }
      f[0] = 1;
      for (int i = 1; i <= n; i++) {
        if (a[i] == a[i - 1]) {
          f[i] = f[i - 1];
        } else {
          f[i] = (f[i - 1] + b[a[i]]) % p;
          b[a[i]] = f[i];
        }
      }
      printf("%lld
    ", f[n]);
    }
    

      

  • 相关阅读:
    GIS Tools for Hadoop 详细介绍
    凤凰涅槃,浴火重生(2013年总结)
    13年我们依然在路上
    HDU 4022 Bombing (map + multiset)
    ArcGIS 10.2 操作SQLite
    hdu1690 Bus System (dijkstra)
    HDU 4704 Sum
    Dark Side of Cloud Storage —— 数据对像的分块消重
    gdb x查看二进制
    信号 signal sigaction补充
  • 原文地址:https://www.cnblogs.com/Accpted/p/11188628.html
Copyright © 2020-2023  润新知