提交 83593f32 编写于 作者: 每日一练社区's avatar 每日一练社区

update exercises

上级 8dceb2d8
......@@ -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);
}
```
......@@ -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;
}
}
......
......@@ -44,7 +44,13 @@ X 国王有一个地宫宝库,是 n×m 个格子的矩阵,每个格子放一
## aop
### before
```cpp
#include <iostream>
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;
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册