Heaps(Contest2080 - 湖南多校对抗赛(2015.05.10)(国防科大学校赛决赛-Semilive)+scu1616)
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)的更多相关文章
- Contest2073 - 湖南多校对抗赛(2015.04.06)
Contest2073 - 湖南多校对抗赛(2015.04.06) Problem A: (More) Multiplication Time Limit: 1 Sec Memory Limit: ...
- Contest2071 - 湖南多校对抗赛(2015.03.28)
Contest2071 - 湖南多校对抗赛(2015.03.28) 本次比赛试题由湖南大学ACM校队原创 http://acm.csu.edu.cn/OnlineJudge/contest.php?c ...
- 湖南多校对抗赛(2015.05.03)Problem A: Twenty-four point
给四个数 问能不能算出24点...我的方法比较烂...920ms 差点TLE.应该有更好的方法. #include<stdio.h> #include<string.h> #i ...
- 湖南多校对抗赛(2015.05.03)Problem B: War
并查集.从后往前加边. #include<stdio.h> #include<string.h> #include<math.h> #include<algo ...
- Contest2089 - 湖南多校对抗赛(2015.05.31) Swipe(csu1648)
Problem E: Swipe Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 100 Solved: 15[Submit][Status][Web ...
- 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 ...
- Clock Pictures(kmp + Contest2075 - 湖南多校对抗赛(2015.04.26))
Problem H: Clock Pictures Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 73 Solved: 18[Submit][Stat ...
- CSU 2136 ——湖南多校对抗赛 I
2136: 统帅三军! Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 55 ...
- 2015.05.15,外语,学习笔记-《Word Power Made Easy》 01 “如何讨论人格特点”
2015.03.17,外语,读书笔记-<Word Power Made Easy> 01 “如何讨论人格特点”学习笔记 SESSIONS 1 本来这些章节都是在一两年前学习的,现在趁给友人 ...
随机推荐
- 关于Nginx设置端口号,在Asp.net 获取不到的,解决办法
不知道你有没有遇到过这样的问题,网站访客多起来后,心里很是高兴,加上了Nginx反向代理,出问题了 原来是这么写的: Request.Url.ToString() 输出是这样的: http://www ...
- [转载]你所不了解的DevOps
DevOps开发运维训练营 一旦建立了创新的文化,即使那些并非科学家或者工程师的人——诗人.演员.记者——也能以团体的形式,接受科学文化的意义.他们信奉创新文化的概念.他们以促进这种文化的方式投票.他 ...
- CLion之C++框架篇-优化框架,引入boost(三)
背景 结合上一篇CLion之C++框架篇-优化框架,单元测试(二),继续进行框架优化!这一版优化引入一个我们日常经常使用的操作库Boost,估算使用频率在70%以上! Boost的优势在哪 ...
- vue2入坑随记(一)-- 初始全家桶
都说Vue2简单,上手容易,但小马过河,自己试了才晓得,除了ES6语法和webpack的配置让你感到陌生,重要的是思路的变换,以前随便拿全局变量和修改dom的锤子不能用了,变换到关注数据本身.vue的 ...
- ESB开发WebService接口
1 概述 在进行系统间集成时经常利用WebService,但是从建立WebService和调用的重复性和维护性的工作量都相当大. 首先简单介绍一下,ESB全称为Enterprise Service B ...
- Java核心技术卷一基础知识-第12章-泛型程序设计-读书笔记
第12章 泛型程序设计 本章内容: * 为什么要使用泛型程序设计 * 定义简单泛型类 * 泛型方法 * 类型变量的限定 * 泛型代码和虚拟机 * 约束与局限性 * 泛型类型的继承规则 * 通配符类型 ...
- 朴素贝叶斯算法简介及python代码实现分析
概念: 贝叶斯定理:贝叶斯理论是以18世纪的一位神学家托马斯.贝叶斯(Thomas Bayes)命名.通常,事件A在事件B(发生)的条件下的概率,与事件B在事件A(发生)的条件下的概率是不一样的:然而 ...
- aaa配置(第十三组)
拓扑 网络情况 A PING B A PING C PC-B PING PC-C 2.R1的配置 a.console线 R1(config)#username admin1 password Admi ...
- vue 国际化i18n 多语言切换
安装 npm install vue-i18n 新建一个文件夹 i18n ,内新建 en.js zh.js index.js 三个文件 准备翻译信息 en.js export default { ho ...
- mysql 开发基础系列18 存储过程和函数(下)
1. 光标的使用(游标) 在存储过程和函数中可以使用光标对结果集进行循环的处理,光标使用包括光标的声明,open ,fetch,close. 下面在存储过程中使用一个光标, 这个举例中光标里的逻辑不重 ...