Problem H: Heaps

Time Limit: 2 Sec  Memory Limit: 128 MB
Submit: 48  Solved: 9
[Submit][Status][Web Board]

Description

Zuosige always has bad luck. Recently, he is in hospital because of pneumonia. While he is taking his injection, he feels extremely bored. However, clever Zuosige comes up with a new game.

Zuosige knows there is a typical problem called Merging Stones. In the problem, you have N heaps of stones and you are going to merging them into one heap. The only restriction is that you can only merging adjacent heaps and the cost of a merging operation is the total number of stones in the two heaps merged. Finally, you are asked to answer the minimum cost to accomplish the merging.

However, Zuosige think this problem is too simple, so he changes it. In his problem, the cost of a merging is a polynomial function of the total number of stones in those two heaps and you are asked to answer the minimum cost.

Input

The first line contains one integer T, indicating the number of test cases.
In one test case, there are several lines.
In the first line, there are an integer N (1<=N<=1000).
In the second line, there are N integers. The i-th integer si (1<=si<=40) indicating the number of stones in the i-th heap.
In the third line, there are an integer m (1<=m<=4).
In the forth line, there are m+1 integers a0, … , am. The polynomial function is P(x)= (a0+a1*x+a2*x2+…+am*xm). (1<=ai<=5)

Output

For each test case, output an integer indicating the answer.

Sample Input

1
5
3 1 8 9 9
2
2 1 2

Sample Output

2840

HINT

转载请注明出处:http://www.cnblogs.com/yuyixingkong/

题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1616

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
using namespace std;
#define ls 2*i
#define rs 2*i+1
#define up(i,x,y) for(i=x;i<=y;i++)
#define down(i,x,y) for(i=x;i>=y;i--)
#define mem(a,x) memset(a,x,sizeof(a))
#define w(a) while(a)
#define LL long long
const double pi = acos(-1.0);
#define N 1005
#define mod 19999997
#define INF 0x3f3f3f3f
#define exp 1e-8 LL dp[N][N],vec[],sum[N];
int s[N],a[N],t,n,m,tot,vis[N][N]; LL col(LL x)
{
LL ans = a[];
int i,j;
up(i,,m)
{
LL tem = ;
up(j,,i) tem*=x;
ans+=tem*a[i];
}
return ans;
} int main()
{
int i,j,k;
scanf("%d",&t);
w(t--)
{
scanf("%d",&n);
mem(sum,);
mem(dp,);
tot=;
up(i,,n)
{
scanf("%d",&s[i]);
sum[i] = sum[i-]+s[i];
tot+=s[i];
}
scanf("%d",&m);
up(i,,m)
{
scanf("%d",&a[i]);
}
up(i,,tot)
{
vec[i]=col((LL)i);
}
up(i,,n) vis[i][i] = i;
vis[][] = ;
int len;
up(len,,n)
{
up(i,,n-len+)
{
j = i+len-;
dp[i][j] = 1LL<<;
up(k,vis[i][j-],vis[i+][j])
{
LL tem = dp[i][k]+dp[k+][j]+vec[sum[j]-sum[i-]];
if(tem<dp[i][j])
{
dp[i][j] = tem;
vis[i][j] = k;
}
}
}
}
printf("%lld\n",dp[][n]);
} return ;
} /**************************************************************
Problem: 1616
User: aking2015
Language: C++
Result: Accepted
Time:620 ms
Memory:13728 kb
****************************************************************/

Heaps(Contest2080 - 湖南多校对抗赛(2015.05.10)(国防科大学校赛决赛-Semilive)+scu1616)的更多相关文章

  1. Contest2073 - 湖南多校对抗赛(2015.04.06)

    Contest2073 - 湖南多校对抗赛(2015.04.06) Problem A: (More) Multiplication Time Limit: 1 Sec  Memory Limit:  ...

  2. Contest2071 - 湖南多校对抗赛(2015.03.28)

    Contest2071 - 湖南多校对抗赛(2015.03.28) 本次比赛试题由湖南大学ACM校队原创 http://acm.csu.edu.cn/OnlineJudge/contest.php?c ...

  3. 湖南多校对抗赛(2015.05.03)Problem A: Twenty-four point

    给四个数 问能不能算出24点...我的方法比较烂...920ms 差点TLE.应该有更好的方法. #include<stdio.h> #include<string.h> #i ...

  4. 湖南多校对抗赛(2015.05.03)Problem B: War

    并查集.从后往前加边. #include<stdio.h> #include<string.h> #include<math.h> #include<algo ...

  5. Contest2089 - 湖南多校对抗赛(2015.05.31) Swipe(csu1648)

    Problem E: Swipe Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 100  Solved: 15[Submit][Status][Web ...

  6. Aquarium Tank(csu1634+几何+二分)Contest2087 - 湖南多校对抗赛(2015.05.24)-G

    Aquarium Tank Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 15  Solved: 4[Submit][Status][Web Board ...

  7. Clock Pictures(kmp + Contest2075 - 湖南多校对抗赛(2015.04.26))

    Problem H: Clock Pictures Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 73  Solved: 18[Submit][Stat ...

  8. CSU 2136 ——湖南多校对抗赛 I

    2136: 统帅三军! Submit Page   Summary   Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 55     ...

  9. 2015.05.15,外语,学习笔记-《Word Power Made Easy》 01 “如何讨论人格特点”

    2015.03.17,外语,读书笔记-<Word Power Made Easy> 01 “如何讨论人格特点”学习笔记 SESSIONS 1 本来这些章节都是在一两年前学习的,现在趁给友人 ...

随机推荐

  1. my eclipse 端口号被占用问题 Mac上

    首先在终端输入 lsof -i :8080 (8080是端口号) 找到进程之后 在终端杀死进程 kill -9 7934 重新运行

  2. js前段开发工具

    http://runjs.cn/?token=e87dac453af5caed08d1771682b0c3f5

  3. Android插件化的兼容性(中):Android P的适配

    Android系统的每次版本升级,都会对原有代码进行重构,这就为插件化带来了麻烦. Android P对插件化的影响,主要体现在两方面,一是它重构了H类中Activity相关的逻辑,另一个是它重构了I ...

  4. iis发布后模板字体不能加载的解决方案

    在使用ace模板的过程中就曾遇到过图标不显示的情况, 1.在iis和vs运行都不能显示图标,添加缺失的字体库后可以访问 2.把项目签入到阿里云时再一次失效,解决方法是添加Mime类型 .woff  a ...

  5. 全面了解移动端DNS域名劫持等杂症:原理、根源、HttpDNS解决方案等

      1.引言 对于互联网,域名是访问的第一跳,而这一跳很多时候会“失足”(尤其是移动端网络),导致访问错误内容.失败连接等,让用户在互联网上畅游的爽快瞬间消失. 而对于这关键的第一跳,包括鹅厂在内的国 ...

  6. HTTP 协议常见的状态码

    HTTP状态码负责表示客户端HTTP请求的返回结果.标记服务器端的处理是否正常.通知出现的错误等工作. 状态码的类别: 记录在RFC2616上的HTTP状态码有40种,再加上WebDAV等的扩展,数量 ...

  7. 机器学习入门02 - 深入了解 (Descending into ML)

    原文链接:https://developers.google.com/machine-learning/crash-course/descending-into-ml/ 线性回归是一种找到最适合一组点 ...

  8. Python中变量的命名

    变量的命名 目标 标识符和关键字 变量的命名规则 0.1 标识符和关键字 1.1 标识符 标示符就是程序员定义的 变量名.函数名 名字 需要有 见名知义 的效果,见下图: 标示符可以由 字母.下划线 ...

  9. 史上最全阿里 Java 面试题总结

    以下为大家整理了阿里巴巴史上最全的 Java 面试题,涉及大量 Java 面试知识点和相关试题. JAVA基础 JAVA中的几种基本数据类型是什么,各自占用多少字节. String类能被继承吗,为什么 ...

  10. php内核之HashTable

    Zend 把与 HashTable 有关的 API 分成了好几类以便于我们查找,这些 API 的返回值大多都是常量SUCCESS 或者 FAILURE. 初始化 HashTable 下面在介绍函数原型 ...