HDU 4972 A Simple Dynamic Programming Problem
Question Link
Reasoning: When only the first and current scores are (1, 2) Or (2, 1), there are two ways to add points. In other cases, there is one case at most, so as long as the number of (1, 2), (2, 1) is counted, and the final result is to judge whether the score difference is 0. If it is not 0, it may be positive or negative, that is double
Code:
#include <cstdio>#include <cstring>const int N = 100005;int t, n, a[N];int solve() { int ans = 1; for (int i = 1; i < n; i++) {if ((a[i] == 2 && a[i - 1] == 1) || (a[i] == 1 && a[i - 1] == 2)) ans++;if (a[i] - a[i - 1] > 3 || a[i - 1] - a[i] > 3) return 0;if (a[i] == a[i - 1] && a[i] != 1) return 0; } if (a[n - 1]) ans *= 2; return ans;}int main() { int cas = 0; scanf("%d", &t); while (t--) {scanf("%d", &n);for (int i = 0; i < n; i++) scanf("%d", &a[i]);printf("Case #%d: %d\n", ++cas, solve()); } return 0;}