题意:

问题是对于所有的长度为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. https双向认证訪问管理后台,採用USBKEY进行系统訪问的身份鉴别,KEY的证书长度大于128位,使用USBKEY登录

    近期项目需求,须要实现用USBKEY识别用户登录,採用https双向认证訪问管理后台管理界面,期间碰到过一些小问题,写出来给大家參考下. 1:前期准备工作 USBKEY 硬件:我买的是飞天诚信 epa ...

  2. php实现类似淘宝最近浏览商品的功能模型代码

    <?php //TempNum 显示临时记录数 $TempNum=5; //setcookie("RecentlyGoods", "12,31,90,39" ...

  3. C# 知识点随手学习网站推荐

    http://www.studyofnet.com/news/list-8881.2-1-1.html

  4. Mataplotlib事例操作

    刚开始需要的文件是和前边的两个连载一起的

  5. KVM技术

    今天是周六,看到一片KVM相关的文章,感觉写得很不错,翻译了,原文在这里:KVM Technology 在开放服务器虚拟化的应用方面,KVM虚拟化技术近年来广受关注.自从2006年10月份诞生以来,其 ...

  6. 关闭和定时显示DIV

    <script type="text/javascript"> $(function(){ $('#ad1').css('display','block'); }) f ...

  7. MongoDB资料汇总专题(转)

    原文地址:http://blog.nosqlfan.com/html/3548.html 1.MongoDB是什么 MongoDB介绍PPT分享 MongoDB GridFS介绍PPT两则 初识 Mo ...

  8. MySQL-怎样使update操作sleep一段时间

    )) a on mytest.id=a.id set mytest.name='xiaowang';

  9. xpath 节点1

    XPath 含有超过 100 个内建的函数.这些函数用于字符串值.数值.日期和时间比较.节点和 QName 处理.序列处理.逻辑值等等. 节点(Node) 在 XPath 中,有七种类型的节点:元素. ...

  10. Xcode5.1.1+ios 7.1.2 免证书真机调试

    Xcode假设不破解.无法真机调试, 也无法编译真机Release文件.仅仅有付费开通Apple开发人员账号,才干申请真机调试.而Xcode进行破解后,结合越狱的iPhone或iPad, 就可以免官方 ...