From 83593f327eed944daf16c14cd0ceabe5aa126ea3 Mon Sep 17 00:00:00 2001 From: zhangzc Date: Thu, 28 Oct 2021 17:06:33 +0800 Subject: [PATCH] update exercises --- .../solution.md" | 122 +++++++++++- .../solution.cpp" | 2 +- .../solution.md" | 175 +++++++++++++++++- 3 files changed, 290 insertions(+), 9 deletions(-) diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/solution.md" index 4e0478b11..e8fef95c0 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\215\225\350\257\215\345\210\206\346\236\220/solution.md" @@ -31,7 +31,8 @@ o 6 ## aop ### before ```cpp - +#include "stdio.h" +#include "string.h" ``` ### after ```cpp @@ -40,21 +41,134 @@ o 6 ## 答案 ```cpp - +int main() +{ + + int a[128] = {0}; + char s[1000]; + scanf("%s", s); + int len = strlen(s); + + int max = 0; + char t = 0; + + for (int i = 0; i < len; i++) + { + a[s[i]]++; + if (max < a[s[i]]) + { + max = a[s[i]]; + t = s[i]; + } + else if (max == a[s[i]]) + { + if (t > s[i]) + { + t = s[i]; + } + } + } + printf("%c\n%d", t, max); +} ``` ## 选项 ### A ```cpp - +int main() +{ + + int a[128] = {0}; + char s[1000]; + scanf("%s", s); + int len = strlen(s); + + int max = 0; + char t = 0; + + for (int i = 0; i < len; i++) + { + a[s[i]]++; + if (max > a[s[i]]) + { + max = a[s[i]]; + t = s[i]; + } + else if (max == a[s[i]]) + { + if (t > s[i]) + { + t = s[i]; + } + } + } + printf("%c\n%d", t, max); +} ``` ### B ```cpp - +int main() +{ + + int a[128] = {0}; + char s[1000]; + scanf("%s", s); + int len = strlen(s); + + int max = 0; + char t = 0; + + for (int i = 0; i < len; i++) + { + a[s[i]]++; + if (max > a[s[i]]) + { + max = a[s[i]]; + t = s[i + 1]; + } + else if (max == a[s[i]]) + { + if (t > s[i]) + { + t = s[i]; + } + } + } + printf("%c\n%d", t, max); +} ``` ### C ```cpp +int main() +{ + + int a[128] = {0}; + char s[1000]; + scanf("%s", s); + int len = strlen(s); + + int max = 0; + char t = 0; + + for (int i = 0; i < len; i++) + { + a[s[i]]++; + if (max < a[s[i]]) + { + max = a[s[i]]; + t = s[i + 1]; + } + else if (max == a[s[i]]) + { + if (t > s[i]) + { + t = s[i]; + } + } + } + printf("%c\n%d", t, max); +} ``` diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/solution.cpp" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/solution.cpp" index e9df2f3b3..86e9fe7ec 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/solution.cpp" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/solution.cpp" @@ -32,7 +32,7 @@ int main() { for (int c = 0; c < v; c++) { - dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u - 1][c]) % MOD; + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u][c]) % MOD; dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j - 1][u - 1][c]) % MOD; } } diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/solution.md" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/solution.md" index 1d1df56ed..cf6be93bc 100644 --- "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/solution.md" +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257/\345\234\260\345\256\253\345\217\226\345\256\235/solution.md" @@ -44,7 +44,13 @@ X 国王有一个地宫宝库,是 n×m 个格子的矩阵,每个格子放一 ## aop ### before ```cpp - +#include +using namespace std; +const int N = 55; +const int MOD = 1e9 + 7; +int dp[N][N][13][14]; +int g[N][N]; +int n, m, k; ``` ### after ```cpp @@ -53,21 +59,182 @@ X 国王有一个地宫宝库,是 n×m 个格子的矩阵,每个格子放一 ## 答案 ```cpp +int main() +{ + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + cin >> g[i][j]; + g[i][j]++; + } + } + dp[1][1][1][g[1][1]] = 1; + dp[1][1][0][0] = 1; + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + for (int u = 0; u <= k; u++) + { + for (int v = 0; v <= 13; v++) + { + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u][v]) % MOD; + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j - 1][u][v]) % MOD; + if (u > 0 && v == g[i][j]) + { + for (int c = 0; c < v; c++) + { + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u - 1][c]) % MOD; + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j - 1][u - 1][c]) % MOD; + } + } + } + } + } + } + int res = 0; + for (int i = 0; i <= 13; i++) + res = (res + dp[n][m][k][i]) % MOD; + cout << res << endl; + return 0; +} ``` ## 选项 ### A ```cpp - +int main() +{ + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + cin >> g[i][j]; + g[i][j]++; + } + } + dp[1][1][1][g[1][1]] = 1; + dp[1][1][0][0] = 1; + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + for (int u = 0; u <= k; u++) + { + for (int v = 0; v <= 13; v++) + { + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u][v]) % MOD; + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j - 1][u][v]) % MOD; + if (u > 0 && v == g[i][j]) + { + for (int c = 0; c < v; c++) + { + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j][u - 1][c]) % MOD; + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j - 1][u - 1][c]) % MOD; + } + } + } + } + } + } + int res = 0; + for (int i = 0; i <= 13; i++) + res = (res + dp[n][m][k][i]) % MOD; + cout << res << endl; + return 0; +} ``` ### B ```cpp - +int main() +{ + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + cin >> g[i][j]; + g[i][j]++; + } + } + dp[1][1][1][g[1][1]] = 1; + dp[1][1][0][0] = 1; + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + for (int u = 0; u <= k; u++) + { + for (int v = 0; v <= 13; v++) + { + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u][v]) % MOD; + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j - 1][u][v]) % MOD; + if (u > 0 && v == g[i][j]) + { + for (int c = 0; c < v; c++) + { + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u - 1][c]) % MOD; + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j][u - 1][c]) % MOD; + } + } + } + } + } + } + int res = 0; + for (int i = 0; i <= 13; i++) + res = (res + dp[n][m][k][i]) % MOD; + cout << res << endl; + return 0; +} ``` ### C ```cpp - +int main() +{ + cin >> n >> m >> k; + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + cin >> g[i][j]; + g[i][j]++; + } + } + dp[1][1][1][g[1][1]] = 1; + dp[1][1][0][0] = 1; + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= m; j++) + { + for (int u = 0; u <= k; u++) + { + for (int v = 0; v <= 13; v++) + { + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u][v]) % MOD; + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j - 1][u][v]) % MOD; + if (u > 0 && v == g[i][j]) + { + for (int c = 0; c < v; c++) + { + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i - 1][j][u][c]) % MOD; + dp[i][j][u][v] = (dp[i][j][u][v] + dp[i][j - 1][u - 1][c]) % MOD; + } + } + } + } + } + } + int res = 0; + for (int i = 0; i <= 13; i++) + res = (res + dp[n][m][k][i]) % MOD; + cout << res << endl; + return 0; +} ``` -- GitLab