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 本来这些章节都是在一两年前学习的,现在趁给友人 ...
随机推荐
- 【腾讯Bugly干货分享】那些年,我们一起写过的“单例模式”
题记 度娘上对设计模式(Design pattern)的定义是:"一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结."它由著名的"四人帮",又称 ...
- 从HTTP/0.9到HTTP/2:一文读懂HTTP协议的历史演变和设计思路
本文原作者阮一峰,作者博客:ruanyifeng.com. 1.引言 HTTP 协议是最重要的互联网基础协议之一,它从最初的仅为浏览网页的目的进化到现在,已经是短连接通信的事实工业标准,最新版本 HT ...
- Python学习笔记【第八篇】:Python内置模块
什么时模块 Python中的模块其实就是XXX.py 文件 模块分类 Python内置模块(标准库) 自定义模块 第三方模块 使用方法 import 模块名 form 模块名 import 方法名 说 ...
- iframe简单框架
<iframe width='738' height='523' class='preview-iframe' scrolling='no' frameborder='0' src='http: ...
- 使用《JAVA面向对象编程》总结
抽象和封装 现实世界是“面向对象”的,面向对象就是采用“现实模拟” 的方法设计和开发程序. 面向对象设计是目前计算软件开发中最流行的技术.面向对象设计的过程就是抽象的过程. 类是对某一类事物的描述,是 ...
- java实操之使用jcraft进行sftp上传下载文件
sftp作为临时的文件存储位置,在某些场合还是有其应景的,比如对账文件存放.需要提供一个上传的工具类.实现方法参考下: pom.xml中引入类库: <dependency> <gro ...
- 浅谈static关键字的四种用法
1.修饰成员变量 在一个person类中,一个成员变量例如 String name,当new2个person()对象时候,这2个对象在堆的位置是不同的,给name赋值张三.李四,这两个对象的name是 ...
- Python中的高级变量类型
高级变量类型 目标 列表 元组 字典 字符串 公共方法 变量高级 知识点回顾 Python 中数据类型可以分为 数字型 和 非数字型 数字型 整型 (int) 浮点型(float) 布尔型(bool) ...
- 【sping揭秘】24、Spring框架对JMS的集成(无环境版,以后学MQ的时候再隆重介绍)& 任务调度和线程池
这个我也不是很了解,那么这个需要好好学习一下了 JMS有2种消息域类型 1. point to point 点对点模式 2.发布订阅模式 publish/subscribe Pub/Sub 模式 传 ...
- 微软Cloud+AI本地化社区贡献指南
本文主要介绍微软Cloud+AI本地化社区,以及通过多种途径贡献本地化的操作指南. 什么是本地化社区 Cloud+AI本地化社区是微软技术社区的组成部分之一,负责对微软官方技术文档本地化的支持工作.微 ...