【递推】 HDU 5459 Jesus Is Here
来源:互联网 发布:ip网络电话交换机 编辑:程序博客网 时间:2024/05/29 09:19
点击打开链接
题意 :求两两之间的下标差和
设
numc [ i ] 为该段 c的数量
addc [ i ] 为该段 所有c的 下标和 (从0 开始
len [ i ] 为该段 长度
ans[ i ] 为答案
addc[i] 因为i-1段前面的c每个增加的len[i-2] 的长度
所以为 addc[ i-2 ] +addc[ i - 1 ] + len[ i- 2 ]*numc[ i- 1 ]
ans[i] 需要计算 i-2 段 中每个 c 与 i-1 段中每个c的距离和
len[i-2]*numc[ i-2 ] - addc[i-2] 表示 i-2段中每个c 距离 i-2 段末尾的距离和
再乘上个numc[ i-1 ] 再加上 addc[i-1] * numc[ i-2 ]
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>#include <string>#include <iostream>#include <algorithm>using namespace std;#include <queue>#include <stack>#include <vector>#include <bitset>#include <list>#include <set>#pragma comment(linker, "/STACK:1024000000,1024000000")#include <map>typedef long long LL;const int INF = 1<<29;const LL mod = 530600414;const int MAXN = 201314+7;const int MAXM = 21101;LL ans[MAXN];LL len[MAXN],numc[MAXN],addc[MAXN];int main(){ len[3]=3,len[4]=5; numc[3]=1,numc[4]=1; addc[3]=0,addc[4]=2; ans[3]=0,ans[4]=0; for(int i=5;i<MAXN;i++) { len[i]=(len[i-2]+len[i-1])%mod; numc[i]=(numc[i-2]+numc[i-1])%mod; addc[i]=(addc[i-2]+addc[i-1]+numc[i-1]*len[i-2])%mod; ans[i]=(ans[i-2]+ans[i-1]+(len[i-2]*numc[i-2]%mod-addc[i-2]+mod)%mod*numc[i-1]%mod + numc[i-2]*addc[i-1]%mod )%mod; } int t,n,cas=0; scanf("%d",&t); while(t--) { scanf("%d",&n); printf("Case #%d: %lld\n",++cas,ans[n]); } return 0;}/**/
0 0
- 【递推】 HDU 5459 Jesus Is Here
- HDU 5459 Jesus Is Here(递推)
- hdu 5459 Jesus Is Here(推公式)
- [HDU 5459]Jesus Is Here[递推][实现]
- HDU-5459 Jesus Is Here(思维递推)
- HDU 5459 Jesus Is Here
- HDU 5459 Jesus Is Here
- HDU 5459 Jesus Is Here
- HDU 5459 Jesus Is Here(递推)——2015 ACM/ICPC Asia Regional Shenyang Online
- hdu 5459 Jesus Is Here 2015沈阳网络赛 递推
- HDU-5459 Jesus Is Here(2015沈阳网赛,递推,思路)
- hdoj 5459 Jesus Is Here 【求公式 递推】
- HDU_5459 Jesus Is Here(递推)
- hdu5459 Jesus Is Here 递推
- Jesus Is Here HDU
- Jesus Is Here HDU
- HDU 5459 Jesus Is Here(DP)
- hdu 5459 Jesus Is Here(dp)
- Linux学习之进程fork()与vfork()
- codeforces 5C C. Longest Regular Bracket Sequence(dp)
- 犀牛——第13章 13.4 兼容性和互用性
- Spring AOP基础知识
- 技术人生:故事之四十谁理解我
- 【递推】 HDU 5459 Jesus Is Here
- 【UML】——类图关系讲解
- 动态规划之Minimum Path Sum
- birch聚类算法的原理与实现
- 双向循环链表
- java SE复习笔记27
- HDU 5253 连接的管道
- 零基础学python-18.7 为什么要使用lambda表达式
- Linux系统管理员不可不知的命令:sudo