HDU 4972 A simple dynamic programming problem

Posted mfmdaoyou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 4972 A simple dynamic programming problem相关的知识,希望对你有一定的参考价值。


随机输出保平安

#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 100005;
int a[N];
int main() {
    int T, cas = 0;
    scanf("%d", &T);
    while(T-- > 0) {
        int n; scanf("%d", &n);
        bool flag = 1;
        a[0] = 0;
        for(int i = 1; i <= n; i ++) {
            scanf("%d", &a[i]);
            if(abs(a[i] - a[i-1]) > 3) flag = false;
            if(a[i] == a[i-1] && a[i] != 1) flag = false;
        }
        if(!flag) {
            printf("Case #%d: 0\n", ++cas);
            continue;
        }
        int ans = 1;
        for(int i = 2; i <= n; i ++) {
            if(a[i] == 1 && a[i-1] == 2) ans ++;
            else if(a[i] == 2 && a[i-1] == 1) ans ++;
        }
        printf("Case #%d: ", ++cas);
        if(a[n] == 0) printf("%d\n", ans);
        else printf("%d\n", ans * 2);
    }
    return 0;
}


以上是关于HDU 4972 A simple dynamic programming problem的主要内容,如果未能解决你的问题,请参考以下文章

HDU 5399Too Simple

HDU 1757 A Simple Math Problem

?HDU 5795 A Simple Nim(简单Nim)

A Simple Math Problem HDU - 5974

HDU-1851-A Simple Game

SDS(Simple Dynamic String)