题意:

问题是对于所有的长度为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. Spring Cloud(十):服务网关zuul(转)

    前面的文章我们介绍了,Eureka用于服务的注册于发现,Feign支持服务的调用以及均衡负载,Hystrix处理服务的熔断防止故障扩散,Spring Cloud Config服务集群配置中心,似乎一个 ...

  2. 抽象类的子类能够new

    纠结了半天,我以为继承了Activity后不能new这里被那个onCreate方法迷惑了以为会出现故障一直没直接创建对象类使用 后来试了试才知道 activity似乎是一个抽象类吧. 你要用他的方法, ...

  3. Linux下Tun/Tap设备通信原理

    Tun/Tap都是虚拟网卡,没有直接映射到物理网卡,是一种纯软件的实现.Tun是三层虚拟设备,能够处理三层即IP包,Tap是二层设备,能处理链路层网络包如以太网包.使用虚拟网络设备,可以实现隧道,如O ...

  4. SharePoint ULS Log Viewer 日志查看器

    SharePoint ULS Log Viewer 日志查看器 项目描写叙述 这是一个Windows应用程序,更加轻松方便查看SharePoint ULS日志文件.支持筛选和简单的视图. 信息 这是一 ...

  5. source insight 配置小记

    0/ Alt + T 打开 Document Options,设置字体,添加 C++ 类型文件 .cc , 删除 Plain txt 类型以避免添加 .txt 文件 1/ Alt + F12 切换函数 ...

  6. linux下解压命令大全(转载)

    转自:http://www.cnblogs.com/eoiioe/archive/2008/09/20/1294681.html .tar 解包:tar xvf FileName.tar打包:tar ...

  7. 开启kbmmw 5.09 中的XML-RPC和 JSON-RPC 服务

    kbmmw 5.09 里面增加了XML-RPC和 JSON-RPC 服务支持,但是默认没有开启. 需要在安装前,修改kbmMWConfig.inc文件. 加入以下定义 {$DEFINE KBMMW_J ...

  8. 整形范围 运行Java代码的机器

    Java 无关 C C++ 有关  移植  整形溢出

  9. 在给mysql数据库备份时,报错: mysqldump: Got error: 145: Table '.\shengdaxcom\pre_forum_thread' is marked as c rashed and should be repaired when using LOCK TABLES

    在给mysql数据库备份时,报错: mysqldump: Got error: 145: Table '.\shengdaxcom\pre_forum_thread' is marked as cra ...

  10. SE18 BADI定义 / SE19 BADI 实现

    明天花30分 再研究下这个: 如果你知道一个BADI名称,可以: 1)使用SE18,输入该BADI名称后,选择Interface,然后查看对应的接口实施样例代码(Example implementat ...