解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include <string.h>
#define N 100010
typedef struct {
int a, b;
} info;
int dp[N][11];
info p[N];
int n;
long long dfs(int pos, int sta) {
if (dp[pos][sta] != -1) return dp[pos][sta];
if (pos == n + 1) return dp[pos][sta] = 0;
long long res = 0;
if (sta == 0) {
long long option1 = dfs(pos + 1, p[pos].b) + 1;
long long option2 = dfs(pos + 1, sta);
if (option1 > option2) {
res = option1;
} else {
res = option2;
}
} else {
if (p[pos].a != sta) {
if (res > dfs(pos + 1, sta)) {
res = res;
} else {
res = dfs(pos + 1, sta);
}
} else {
long long option1 = dfs(pos + 1, p[pos].b) + 1;
long long option2 = dfs(pos + 1, sta);
if (option1 > option2) {
res = option1;
} else {
res = option2;
}
}
}
return dp[pos][sta] = res;
}
void solve() {
memset(dp, -1, sizeof(dp));
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
p[i].b = x % 10;
while (x) {
if (x / 10 == 0) {
p[i].a = x;
}
x /= 10;
}
p[i].a++;
p[i].b++;
}
printf("%d\n", n - dfs(1, 0));
}
int main() {
solve();
return 0;
}
0.0分
4 人评分
printf基础练习2 (C语言代码)浏览:746 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:507 |
DNA (C语言描述,数据结构)浏览:862 |
A+B for Input-Output Practice (III) (C语言代码)浏览:569 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:686 |
C语言训练-求车速 (C语言代码)浏览:814 |
简单的a+b (Java代码)浏览:753 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)(简单版)浏览:560 |
WU-IP判断 (C++代码)(一种有趣的实现方法)浏览:1498 |
IP判断 (C语言代码)浏览:499 |