HDU 5459 Jesus Is Here(DP)

DP记录答案,更新DP的时候要用到每个cff到其字符串末尾的长度和pos,以及每个cff到其字符串开头的长度和,然后记录一下每个字符串中cff的个数cnt,和字符串长度len,然后乱搞一下就成了。

#pragma warning(disable:4996)
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 201320;
const LL mod = 530600414;
LL dp[N], pre[N], pos[N], cnt[N], len[N];

void work(){
    dp[3] = dp[4] = 0;
    pre[3] = 0; pre[4] = 2;
    pos[3] = 3; pos[4] = 3;
    cnt[3] = cnt[4] = 1;
    len[3] = 3; len[4] = 5;

    for (int i = 5; i < N; i++){
        len[i] = (len[i - 1] + len[i - 2]) % mod;
        cnt[i] = (cnt[i - 1] + cnt[i - 2]) % mod;
        pos[i] = (pos[i - 1] + pos[i - 2] + cnt[i - 2] * len[i - 1]) % mod;
        pre[i] = (pre[i - 2] + pre[i - 1] + cnt[i - 1] * len[i - 2]) % mod;
        dp[i] = (dp[i - 1] + dp[i - 2] + pos[i - 2] * cnt[i - 1] + pre[i - 1] * cnt[i - 2]) % mod;
    }

}

int main(){
    work();
    int T; scanf("%d", &T);
    int kase = 1;
    while (T--){
        int n; scanf("%d", &n);
        printf("Case #%d: %lld\n", kase++, dp[n]);
    }
    return 0;
}


你可能感兴趣的:(HDU 5459 Jesus Is Here(DP))