博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Heaps(Contest2080 - 湖南多校对抗赛(2015.05.10)(国防科大学校赛决赛-Semilive)+scu1616)...
阅读量:5162 次
发布时间:2019-06-13

本文共 2977 字,大约阅读时间需要 9 分钟。

Problem H: Heaps

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

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

153 1 8 9 9 22 1 2

Sample Output

2840

HINT

转载请注明出处:

题目链接:

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 using namespace std; 13 #define ls 2*i 14 #define rs 2*i+1 15 #define up(i,x,y) for(i=x;i<=y;i++) 16 #define down(i,x,y) for(i=x;i>=y;i--) 17 #define mem(a,x) memset(a,x,sizeof(a)) 18 #define w(a) while(a) 19 #define LL long long 20 const double pi = acos(-1.0); 21 #define N 1005 22 #define mod 19999997 23 #define INF 0x3f3f3f3f 24 #define exp 1e-8 25 26 LL dp[N][N],vec[50000],sum[N]; 27 int s[N],a[N],t,n,m,tot,vis[N][N]; 28 29 LL col(LL x) 30 { 31 LL ans = a[0]; 32 int i,j; 33 up(i,1,m) 34 { 35 LL tem = 1; 36 up(j,1,i) tem*=x; 37 ans+=tem*a[i]; 38 } 39 return ans; 40 } 41 42 int main() 43 { 44 int i,j,k; 45 scanf("%d",&t); 46 w(t--) 47 { 48 scanf("%d",&n); 49 mem(sum,0); 50 mem(dp,0); 51 tot=0; 52 up(i,1,n) 53 { 54 scanf("%d",&s[i]); 55 sum[i] = sum[i-1]+s[i]; 56 tot+=s[i]; 57 } 58 scanf("%d",&m); 59 up(i,0,m) 60 { 61 scanf("%d",&a[i]); 62 } 63 up(i,1,tot) 64 { 65 vec[i]=col((LL)i); 66 } 67 up(i,1,n) vis[i][i] = i; 68 vis[0][1] = 1; 69 int len; 70 up(len,2,n) 71 { 72 up(i,1,n-len+1) 73 { 74 j = i+len-1; 75 dp[i][j] = 1LL<<60; 76 up(k,vis[i][j-1],vis[i+1][j]) 77 { 78 LL tem = dp[i][k]+dp[k+1][j]+vec[sum[j]-sum[i-1]]; 79 if(tem

 

转载于:https://www.cnblogs.com/yuyixingkong/p/4498693.html

你可能感兴趣的文章
Problem E: Automatic Editing
查看>>
SpringBoot 使用 MyBatis 分页插件 PageHelper 进行分页查询
查看>>
《DSP using MATLAB》Problem 6.17
查看>>
微信公众平台开发实战Java版之如何网页授权获取用户基本信息
查看>>
一周TDD小结
查看>>
sizeof与strlen的用法
查看>>
Linux 下常见目录及其功能
查看>>
开源框架中常用的php函数
查看>>
nginx 的提升多个小文件访问的性能模块
查看>>
set&map
查看>>
集合类总结
查看>>
4.AE中的缩放,书签
查看>>
CVE-2014-6321 && MS14-066 Microsoft Schannel Remote Code Execution Vulnerability Analysis
查看>>
给一次重新选择的机会_您还会选择程序员吗?
查看>>
Mysql MHA高可用集群架构
查看>>
心急的C小加
查看>>
编译原理 First,Follow,select集求法
查看>>
java 浅拷贝和深拷贝
查看>>
vue实例中中data属性三种写法
查看>>
uva1636 - Headshot(条件概率)
查看>>