比赛链接:Here

1391A. Suborrays

简单构造题,

Codeforces Round #663 (Div. 2) (A~C题,C题 Good) - 图1 放最前面,接着补 Codeforces Round #663 (Div. 2) (A~C题,C题 Good) - 图2 ~ Codeforces Round #663 (Div. 2) (A~C题,C题 Good) - 图3 即可

1391B. Fix You

Codeforces Round #663 (Div. 2) (A~C题,C题 Good) - 图4#card=math&code=%281%2C1%29) -> Codeforces Round #663 (Div. 2) (A~C题,C题 Good) - 图5#card=math&code=%28n%2Cm%29) 统计相应个数的 RD 即可

  1. char a[110][110];
  2. int main() {
  3. cin.tie(nullptr)->sync_with_stdio(false);
  4. int _; for (cin >> _; _--;) {
  5. int n, m;
  6. cin >> n >> m;
  7. for (int i = 1; i <= n; ++i)
  8. for (int j = 1 ; j <= m; ++j) cin >> a[i][j];
  9. int sum = 0;
  10. for (int i = 1; i < m; ++i) if (a[n][i] != 'R')sum += 1;
  11. for (int i = 1; i < n; ++i) if (a[i][m] != 'D')sum += 1;
  12. cout << sum << "\n";
  13. }
  14. }

1391C. Cyclic Permutations (Good)

先说结论:Codeforces Round #663 (Div. 2) (A~C题,C题 Good) - 图6
对于任意的循环排列,例如 [4, 2,3,1,5,6] 它包含许多长度为3的循环: [1,2,3],[1,3,5],[3,4,5] 。请注意,所有列出的循环都包含仅从一个i选项中获得的节点。我们可以将其概括为以下几点。如果对于任何一个i,我们在它的两边做边,这将创建一个长度为3的简单循环。证明很简单。
因此,最多只能有一个峰值,即元素 Codeforces Round #663 (Div. 2) (A~C题,C题 Good) - 图7 ~ 所有非循环排列都会增加,然后达到 Codeforces Round #663 (Div. 2) (A~C题,C题 Good) - 图8 ,最后减少。这些形式上称为单峰置换,很容易看出,任何单峰置换都形成一棵树,因此不包含简单的循环-除了n之外,每个元素都有一个唯一定义的父元素。
我们可以通过将数字n,n相加来构造任何单峰排列−1,…,1按相同顺序排列成一个三角形。例如,[2,3,4,1]可以通过先将4,3,2推到前面,最后将1推到后面来构造。因此,对于除n之外的每个元素,我们可以选择将其推到前面或后面,使路径总数等于 Codeforces Round #663 (Div. 2) (A~C题,C题 Good) - 图9 .

  1. const int mod = 1e9 + 7;
  2. int main() {
  3. cin.tie(nullptr)->sync_with_stdio(false);
  4. int n;
  5. cin >> n;
  6. ll a = 1, b = 1;
  7. for (int i = 1; i <= n; ++i) a = a * i % mod;
  8. for (int i = 1; i < n; ++i) b = b * 2 % mod;
  9. cout << (a + mod - b) % mod;
  10. }