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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值