Exercises
$DP $.
$DP [i][j]$ represents to the $i$ letter, and the letter in the $j$ layer of the scheme number, transfer analysis will know.
#include <bits/stdc++.h>using namespace std;const long Long mod = 1e9 + 7;const int maxn = + 10;int N, F;char o P[maxn][5];long long Dp[maxn][maxn];int Main () { scanf ("%d", &n); for (int i = 1; I <= n; i + +) { scanf ("%s", Op[i]); } DP[1][1] = 1; for (int i = 2; I <= n, i + +) { if (op[i-1][0] = = ' F ') {for (int j = 1; J <= I-1; j + +) { dp[i][j + 1] = Dp[i-1][j]; } } else { long long sum = 0; for (int j = i-1; J >= 1; J--) { sum = (sum + dp[i-1][j])% MoD; DP[I][J] = sum;}} } /* for (int i = 1; I <= n; i + +) {for (int j = 1; J <= I; j + +) { printf ("%lld", Dp[i][j]); } printf ("\ n"); } */ long long ans = 0; if (op[n][0] = = ' F ') ans = 0; else {for (int j = 1; J <= N; j + +) { ans = (ans + dp[n][j])% mod; } printf ("%lld\n", ans); } return 0;}
Codeforces 909C Python indentation