题意:

问题是对于所有的长度为n,且$1<=ai<=n$的整数序列求 $\prod_{i=1}^{n-2}{max \{w_i,w_{i+1},w_{i+2}}\}$ 之和。

解法:

首先设dp状态为 $f(i,j,k)$ ,长度为$i+3$的,最大值为k,且最大值出现的位置集合为j的序列的乘积和。

显然可以由 $f(i-1,j2,k2)$ 转移到 $f(i,j,k)$,做前缀和优化,总效率$O(n^2 * 2^6)$

重新设计dp状态,改变j的定义,j表示最大值最后出现的位置。

这样对于状态 $f(i,j,k)$,我们确定了长度为$i+j$的序列的值,并且确定了$a(i+j+1)...a(i+2)<k$ 。

假设之前的三个数字最大值为$k2$,之后的最大值为k,这样的的话只要分为 $k>k2, k<k2, k=k2$ 讨论即可得出答案。

再加以前缀和优化,总效率$O(n^2)$。

 #include <iostream>
#include <cstdio>
#include <cstring> #define LL long long
#define N 2010
#define P 1000000007LL using namespace std; int n;
LL w[N],S[N],S2[N],f[N][][N]; LL sum(LL S[],int l,int r)
{
if(l>r) return 0LL;
LL ans = S[r]+P-S[l-];
if(ans>=P) ans-=P;
return ans;
} int main()
{
// freopen("test.txt","r",stdin);
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++) scanf("%lld",&w[i]);
for(int i=;i<=n-;i++)
for(int k=;k<=n;k++)
f[i][][k]=, f[i][][k]=, f[i][][k]=;
for(int x1=;x1<=n;x1++)
for(int x2=x1;x2<=n;x2++) f[][][x2]++;
for(int x1=;x1<=n;x1++) f[][][x1]=;
for(int i=;i<=n-;i++)
{
for(int k=;k<=n;k++)
{
S[k] = S[k-] +f[i-][][k];
S2[k] = S2[k-]+f[i-][][k]*(k-)*(k-);
S2[k] += f[i-][][k]*(k-);
S2[k] += f[i-][][k];
}
for(int k=;k<=n;k++)
{
f[i][][k] += sum(S2,,k-);
f[i][][k] += f[i-][][k];
f[i][][k] += f[i-][][k];
f[i][][k] += f[i-][][k]*(k-)*(k-);
f[i][][k] += f[i-][][k]*(k-);
f[i][][k] += f[i-][][k];
f[i][][k] += sum(S,k+,n);
f[i][][k] += sum(S,k+,n)*k;
f[i][][k] += sum(S,k+,n)*k*k;
f[i][][k] = f[i][][k]%P * w[k]%P;
f[i][][k] = f[i][][k]%P * w[k]%P;
f[i][][k] = f[i][][k]%P * w[k]%P;
}
}
LL ans=;
for(int k=;k<=n;k++)
{
ans += f[n-][][k]*(k-)*(k-);
ans += f[n-][][k]*(k-);
ans += f[n-][][k];
ans %= P;
}
cout << ans << endl;
}
return ;
}

Even Three is Odd的更多相关文章

  1. [LeetCode] Odd Even Linked List 奇偶链表

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  2. Odd Even Linked List

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  3. LeetCode 328. Odd Even Linked List

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  4. tr:even 与tr:odd

    :even匹配所有索引值为偶数的元素,从 0 开始计数查找表格的1.3.5...行(即索引值0.2.4...)<table> <tr><td>Header 1< ...

  5. Leetcode Odd Even Linked List

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  6. CSS3伪类选择器:nth-child()(nth-child(odd)/nth-child(even))

    nth-child(odd):奇数 nth-child(even):偶数 使用时,如果是精确到数字时,切记是从同一级别的元素开始计算,而不是指定某个类才开始计算. 比如: <li>< ...

  7. [CareerCup] 5.6 Swap Odd and Even Bits 交换奇偶位

    5.6 Write a program to swap odd and even bits in an integer with as few instructions as possible (e. ...

  8. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  9. 328. Odd Even Linked List——多利用fake_head

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  10. 越狱Season 1-Episode 12:Odd Man Out

    Season 1-Episode 12:Odd Man Out -Sorry to keep you waiting. 抱歉让你等了半天 -Oh, it's, uh, not a problem. 嗯 ...

随机推荐

  1. [C#]使用 C# 代码实现拓扑排序 dotNet Core WEB程序使用 Nginx反向代理 C#里面获得应用程序的当前路径 关于Nginx设置端口号,在Asp.net 获取不到的,解决办法 .Net程序员 初学Ubuntu ,配置Nignix 夜深了,写了个JQuery的省市区三级级联效果

    [C#]使用 C# 代码实现拓扑排序   目录 0.参考资料 1.介绍 2.原理 3.实现 4.深度优先搜索实现 回到顶部 0.参考资料 尊重他人的劳动成果,贴上参考的资料地址,本文仅作学习记录之用. ...

  2. Java、C++、Python、Ruby、PHP、C#和JavaScript的理解

    Java.C++.Python.Ruby.PHP.C#和JavaScript和日本动漫里的那些大家熟悉的动漫人物结合起来.依据他们的身世.个人经历来生动的表达各编程语言的发展历程.原文内容例如以下:  ...

  3. 一步一步教你在 Android 里创建自己的账号系统(一)

    大家假设喜欢我的博客,请关注一下我的微博,请点击这里(http://weibo.com/kifile),谢谢 转载请标明出处(http://blog.csdn.net/kifile),再次感谢 大家在 ...

  4. 用callgraph生成的两张函数调用关系图

    参考这里,感觉很Cool吧. Linux-0.11函数调用关系图: QEMU函数调用关系图:

  5. Linux高端内存

    Linux高端内存是针对物理内存来说的,虚拟内存没有高端这个概念.Linux系统将虚拟内存分为两个部分,即用户地 址空间和内核地址空间,对于32位系统来说,虚拟地址空间为4GB,其中用户空间范围为0- ...

  6. cubietruck制作刷新lubuntu-kernel

    一:安装交叉编译工具链以及相应的工具(系统最好是ubutnu-64位-server) sudo apt-get install g++ sudo apt-get install libncurses5 ...

  7. ArrayList概述

    一. ArrayList概述: ArrayList是基于数组实现的,是一个动态数组,其容量能自动增长,类似于C语言中的动态申请内存,动态增长内存. ArrayList不是线程安全的,只能用在单线程环境 ...

  8. c# winform中预防窗体重复打开

      当窗体以非模态形式打开的时候,有可能出现重复打开的情形,利用以下的代码可以预防重复打开! foreach (Form f in Application.OpenForms) { if (f.Nam ...

  9. mybatis入门(八)

    mybatis入门---更新和删除 <!-- 删除用户 --> <delete id="deleteUser" parameterType="java. ...

  10. svn下载

    首先介绍的是SVN安装包的下载,分别包括服务器版和客户端版 下载地址:http://subversion.apache.org/packages.html 打开后,点击Windows 分别下载客户端( ...